#include <iostream>
#include <string>
using namespace std;
int main() {
string sentences, keyword;
bool found = false;
// Prompt the user to enter a sequence of sentences
cout << "Enter a sequence of sentences: ";
getline(cin, sentences);
// Prompt the user to enter a keyword to search for
cout << "Enter a keyword: ";
cin >> keyword;
// Tokenize the sentences by splitting them into substrings using the delimiter '.'
size_t start = 0, end = 0;
while ((end = sentences.find('.', start)) != string::npos) {
// Get the current sentence
string sentence = sentences.substr(start, end - start);
// Check if the sentence contains the keyword
if (sentence.find(keyword) != string::npos) {
// Display the sentence that contains the keyword
cout << sentence << "." << endl;
found = true;
}
// Move to the next sentence
start = end + 1;
}
// Check if the keyword was not found in any sentence
if (!found) {
cout << "The keyword was not found in any sentence." << endl;
}
return 0;
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.