#include #include #include #include #include using namespace std; #define pb push_back #define mp make_pair const string correctStart = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_йцукенгшщзхъфывапролджэячсмитьбюёЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮЁ"; const string correctSymb = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_йцукенгшщзхъфывапролджэячсмитьбюёЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮЁ1234567890"; vector> state = { { 0, 0, 1, 0, 0}, {0, 0, 0, 2 ,0}, {0, 0, 0, 2 ,0}, {0, 0, 0, 2 ,0}, {0, 0, 0, 2 ,0}, {0, 0, 0, 2 ,0} }; bool checkFirstSymb(string s) { for (int i = 0; i < correctStart.size(); i++) if (s[0] == correctStart[i]) return true; return false; } bool checkFullString(string s) { for (int i = 1; i < s.size(); i++) { bool isCorrect = false; for (int j = 0; j < correctSymb.size() && !isCorrect; j++) if (s[i] == correctSymb[j]) isCorrect = true; if (!isCorrect) return false; } return true; } void printAns(vector a, set b) { string notFound = "No correct substrings found"; cout << "Found all correct substrings: \n"; if (a.size() > 0) for (int i = 0; i < a.size(); i++) cout << a[i] << ' '; else cout << notFound; cout << "\nFound unique correct substrings: \n"; set ::iterator it; if (b.size() > 0) for (it = b.begin(); it != b.end(); ++it) cout << *it << " "; else cout << notFound; } pair, set> findSubstrings(string s) { vector ansFull; set ansUnique; bool isFind = false; string toPush; for (int i = 0; i < s.size(); i++) { isFind = false; for (int j = 0; j < correctStart.size(); j++) if (s[i] == correctStart[j]) { isFind = true; toPush = ""; for (int c = i; c < s.size() && isFind; c++) { isFind = false; for (int k = 0; k < correctSymb.size() && !isFind; k++) if (s[c] == correctSymb[k]) isFind = true; if (isFind) { toPush += s[c]; ansFull.pb(toPush); if (ansUnique.find(toPush) == ansUnique.end()) ansUnique.insert(toPush); } } } } return mp(ansFull, ansUnique); } void checkStringForCorrect(string s) { if (checkFirstSymb(s)) if (checkFullString(s)) cout << "True\n"; else cout << "False\n"; else cout << "False\n"; } int main(int argc, char* argv[]) { setlocale(LC_ALL, "Russian"); string input; cout << "Enter your string:\n"; getline(cin, input); cout << "The result of checking the correctness of the entered string: "; checkStringForCorrect(input); pair, set> ans = findSubstrings(input); printAns(ans.first, ans.second); }