Created
December 1, 2021 22:35
-
-
Save buza-me/49266c6ec353e404e935688c22e83bcb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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