Advertisement
Georgiy031

Untitled

Jun 12th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     setlocale(LC_ALL, "Russian");
  10.  
  11.     string s;
  12.     vector<string> v;
  13.     int len = 0;
  14.  
  15.     cout << "Введите строку: " << endl;
  16.     cin >> s;
  17.  
  18.     for (int i = 0; i < s.size(); ++i) {
  19.         if (s[i] % 2 == 0) {
  20.             ++len;
  21.         }
  22.         else {
  23.             if (len > 2) {
  24.                 v.push_back(s.substr(i - len, len));
  25.             }
  26.             len = 0;
  27.         }
  28.     }
  29.     if (len > 2) {
  30.         v.push_back(s.substr(s.size() - len, len));
  31.     }
  32.  
  33.     if (v.empty()) {
  34.         cout << "Подстроки с символами четного кода длины больше 2 не найдены." << endl;
  35.     }
  36.     else {
  37.         cout << "Подстроки символов с четным кодом длины больше 2:" << endl;
  38.         for (string& substr : v) {
  39.             cout << substr << endl;
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement