Advertisement
MadCortez

Untitled

Nov 18th, 2021
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. #include <string>
  5. #include <string.h>
  6.  
  7. using namespace std;
  8.  
  9. #define pb push_back
  10. #define mp make_pair
  11.  
  12. const string correctStart = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_йцукенгшщзхъфывапролджэячсмитьбюёЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮЁ";
  13. const string correctSymb = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_йцукенгшщзхъфывапролджэячсмитьбюёЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮЁ1234567890";
  14.  
  15. bool checkFirstSymb(string s) {
  16.     for (int i = 0; i < correctStart.size(); i++)
  17.         if (s[0] == correctStart[i])
  18.             return true;
  19.     return false;
  20. }
  21.  
  22. bool checkFullString(string s) {
  23.     for (int i = 1; i < s.size(); i++) {
  24.         bool isCorrect = false;
  25.         for (int j = 0; j < correctSymb.size() && !isCorrect; j++)
  26.             if (s[i] == correctSymb[j])
  27.                 isCorrect = true;
  28.         if (!isCorrect)
  29.             return false;
  30.     }
  31.     return true;
  32. }
  33.  
  34. void printAns(vector<string> a, set<string> b) {
  35.     cout << "Found all correct substrings: \n";
  36.     for (int i = 0; i < a.size(); i++)
  37.         cout << a[i] << ' ';
  38.     cout << "\nFound unique correct substrings: \n";
  39.     set<string> ::iterator it;
  40.     for (it = b.begin(); it != b.end(); ++it)
  41.         cout << *it << " ";
  42. }
  43.  
  44. pair<vector<string>, set<string>> findSubstrings(string s) {
  45.     vector<string> ansFull;
  46.     set<string> ansUnique;
  47.     bool isFind = false;
  48.     string toPush;
  49.     for (int i = 0; i < s.size(); i++) {
  50.         isFind = false;
  51.         for (int j = 0; j < correctStart.size(); j++)
  52.             if (s[i] == correctStart[j]) {
  53.                 isFind = true;
  54.                 toPush = "";
  55.                 for (int c = i; c < s.size() && isFind; c++) {
  56.                     isFind = false;
  57.                     for (int k = 0; k < correctSymb.size() && !isFind; k++)
  58.                         if (s[c] == correctSymb[k])
  59.                             isFind = true;
  60.                     if (isFind) {
  61.                         toPush += s[c];
  62.                         ansFull.pb(toPush);
  63.                         if (ansUnique.find(toPush) == ansUnique.end())
  64.                             ansUnique.insert(toPush);
  65.                     }
  66.                 }
  67.             }
  68.     }
  69.     return mp(ansFull, ansUnique);
  70. }
  71.  
  72. void checkStringForCorrect(string s) {
  73.     if (checkFirstSymb(s))
  74.         if (checkFullString(s))
  75.             cout << "True\n";
  76.         else
  77.             cout << "False\n";
  78.     else
  79.         cout << "False\n";
  80. }
  81.  
  82. int main(int argc, char* argv[]) {
  83.     setlocale(LC_ALL, "Russian");
  84.     string input;
  85.     cout << "Enter your string:\n";
  86.     getline(cin, input);
  87.     cout << "The result of checking the correctness of the entered string: ";
  88.     checkStringForCorrect(input);
  89.     pair<vector<string>, set<string>> ans = findSubstrings(input);
  90.     printAns(ans.first, ans.second);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement