-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings_find.cc
More file actions
52 lines (51 loc) · 1.22 KB
/
strings_find.cc
File metadata and controls
52 lines (51 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int
main (int argc, char *argv[])
{
string sentence;
string keys;
cout << "Enter the first sentence." << endl;
getline (cin, sentence);
cout << "Enter the key lettes that you want to use for search" << endl;
cin >> keys;
bool check = true;
bool found = false;
size_t indx = 0;
size_t length = 0;
for (size_t i {} ; i < sentence.length(); i++)
{
if (isspace(sentence[i])) {
if (found) {
cout << sentence.substr(indx, length) << endl;
}
check = true;
indx = 0;
length = 0;
continue;
}
if (check) {
for (auto c: keys)
{
if (tolower(sentence[i]) == tolower(c)) {
indx = i;
length = 1;
found = true;
break;
} else {
found = false;
}
}
check = false;
continue;
}
if (found) {
length++;
}
}
if (found) {
cout << sentence.substr(indx, length) << endl;
}
}