include iostream include vector include string include algorithm bool

 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
bool checkRuss(const std::string &str)
{
return (str.find_first_not_of("абвгдеёжзиклмнопрстуфхцчьыъэюяАБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧЬЫЪЭЮЯ") == std::string::npos);
}
bool checkRussAndLat(const std::string &str)
{
return (str.find_first_of("абвгдеёжзиклмнопрстуфхцчьыъэюяАБВГДЕЁЖЗИКЛМНОПРСТУФХЦЧЬЫЪЭЮЯ") != std::string::npos)
&& (str.find_first_of("abdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") != std::string::npos);
}
bool checkNumbersAndOther(const std::string &str)
{
for (int i = 0; i < str.length(); i++)
if (str[i] < 'a')
return true;
return false;
}
void printVector(const std::vector<std::string> &v)
{
for (int i = 0; i < v.size(); i++)
std::cout << "\t" << v[i] << std::endl;
}
int main(int argc, char *argv[])
{
std::vector<std::string> strings;
strings.push_back("Разраз");
strings.push_back("Test Test");
strings.push_back("123456");
strings.push_back("1234Test");
strings.push_back("Раз два Test");
std::cout << "Input array:" << std::endl;
printVector(strings);
std::vector<std::string> onlyRuss, russAndLat, numbersAndOther;
for (int i = 0; i < strings.size(); i++)
{
std::string &str = strings[i];
bool hasRuss = checkRuss(str);
bool hasLat = checkRussAndLat(str);
bool hasNums = checkNumbersAndOther(str);
if (hasRuss && !hasLat && !hasNums)
onlyRuss.push_back(str);
if (hasRuss && hasLat)
russAndLat.push_back(str);
if (hasNums)
numbersAndOther.push_back(str);
}
std::cout << "Only russian array: " << std::endl;
printVector(onlyRuss);
std::cout << "Russian and Latin array: " << std::endl;
printVector(russAndLat);
std::cout << "Numbers and other array: " << std::endl;
printVector(numbersAndOther);
system("PAUSE");
return 0;
}