Skip to content

Instantly share code, notes, and snippets.

@scdekov
Created December 10, 2014 13:53
Show Gist options
  • Save scdekov/a42ac81a80f498c64916 to your computer and use it in GitHub Desktop.
Save scdekov/a42ac81a80f498c64916 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;
vector<string> split(string text)
{
vector<string> words;
int lastSpaceIx = 0;
for (int i = 0; i < text.length(); ++i)
{
if (text[i] == " ")
{
words.push_back(lastSpaceIx, i);
lastSpaceIx = i;
}
}
return words;
}
int main()
{
string text = "In computing, a hash table (hash map) is a data structure used to implement an associative array, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the correct value can be found."
vector<string> words = split(text);
for(int i = 0; i<words.size();i++)
{
cout<<words[i]<<", ";
}
cout<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment