-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvanced_treta_zadacha.cpp
54 lines (45 loc) · 1.17 KB
/
advanced_treta_zadacha.cpp
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
53
54
#include <iostream>
#include <algorithm>
using namespace std;
bool checkString(string result)
{
return none_of(result.begin(), result.end(), [](const char& c)
{
return !(isalpha(c) || isdigit(c) || c == ' ');
});
}
string validateInput(string prompt)
{
string result;
while (true)
{
cin.clear();
cin.sync();
cout << prompt;
getline(cin, result);
if (checkString(result))
{
break;
}
else
cin.clear();
cout << "Invalid input! Input must contain only small or capital letters and numbers." << endl;
}
return result;
}
int main()
{
int counter = 0;
string::size_type start = 0;
string firstRow = validateInput("Enter first string: ");
string secondRow = validateInput("Enter second string: ");
transform(firstRow.begin(), firstRow.end(), firstRow.begin(), ::tolower);
transform(secondRow.begin(), secondRow.end(), secondRow.begin(), ::tolower);
while ((start = firstRow.find(secondRow, start)) != string::npos)
{
++counter;
start += secondRow.length();
}
cout << counter << endl;
return 0;
}