Skip to content

Instantly share code, notes, and snippets.

@Caesar-Victory
Created April 12, 2023 14:01
Show Gist options
  • Select an option

  • Save Caesar-Victory/677000356b0ad3ba802b68e69fbc9ca5 to your computer and use it in GitHub Desktop.

Select an option

Save Caesar-Victory/677000356b0ad3ba802b68e69fbc9ca5 to your computer and use it in GitHub Desktop.
#C++
auto getWords = [&](string &sentence) -> vector<string> {
int n = sentence.size();
vector<string> ans;
for (int i = 0; i < n; i++) {
string word="";
int j = i;
while (j < n && (!isblank(sentence[j]))) {
word += sentence[j];
j ++;
}
ans.push_back(word);
i = j;
}
return ans;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment