Skip to content

Instantly share code, notes, and snippets.

@buza-me
Created December 1, 2021 22:35
Show Gist options
  • Save buza-me/49266c6ec353e404e935688c22e83bcb to your computer and use it in GitHub Desktop.
Save buza-me/49266c6ec353e404e935688c22e83bcb to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string words;
string filter;
string delimiter = " ";
vector<string> splitwords;
cout << "Please, enter words: ";
getline (cin, words);
cout << "Please, enter desired start letter(s): ";
getline (cin, filter);
while(words.size())
{
int index = words.find(delimiter);
if(index != string::npos)
{
splitwords.push_back(words.substr(0, index));
words = words.substr(index + delimiter.size());
if(words.size() == 0) splitwords.push_back(words);
}
else
{
splitwords.push_back(words);
words = "";
}
}
for(int i = 0; i < splitwords.size(); i++) {
if (splitwords[i].rfind(filter, 0) == 0)
{
cout << splitwords[i] << endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment