Advertisement
Leeen

ЯиМП №3 вар 9

Apr 5th, 2019
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include "pch.h"
  2. #include <string>
  3. #include <fstream>
  4. #include <vector>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. bool rightWord(string a)
  10. {
  11.     string glass("аеёиоуыэюяАЕЁИОУЫЭЮЯ");
  12.     if (a.size() > 6) return false;
  13.     bool containDigit = false;
  14.     bool containChar = false;
  15.     bool gl = false;
  16.     for (int i = 0; i < a.size(); i++) {
  17.         if (glass.find(a[i]) != string::npos) gl = true;
  18.         if (a[i] >= 'А' && a[i] <= 'я' || a[i] == 'Ё' || a[i] == 'ё')
  19.             containChar = true;
  20.         else if (isdigit(a[i]))
  21.             containDigit = true;
  22.         else
  23.             return false;
  24.  
  25.     }
  26.  
  27.     return containDigit && gl;
  28. }
  29.  
  30. vector<string> getRightWord(string s)
  31. {
  32.     vector<string> right;
  33.     char ch;
  34.     string a = "";
  35.     for (int i = 0; i < s.length(); i++)
  36.     {
  37.         ch = s[i];
  38.         //записываем слово, пока не встретится пробел
  39.         if (ch != ' ' && ch != '\0' && ch != '\n') {
  40.             a += ch;
  41.         }
  42.         else {
  43.             if (rightWord(a))
  44.                 right.push_back(a);
  45.                
  46.             a = "";
  47.         }
  48.     }
  49.     return right;
  50. }
  51. int main()
  52. {
  53.     setlocale(LC_ALL, ".1251");
  54.  
  55.     ifstream fileIn;
  56.     fileIn.open("input.txt");
  57.     if (!fileIn)
  58.     {
  59.         cout << "Error: File not found" << endl;
  60.         system("pause");
  61.         return 0;
  62.     }
  63.  
  64.     string ch;
  65.  
  66.     string a;
  67.     cout << "Finded words: " << endl;
  68.    
  69.     while (!fileIn.eof())
  70.     {
  71.         string buffer;
  72.         getline(fileIn, buffer);
  73.         a += buffer;
  74.     }
  75.     fileIn.close();
  76.  
  77.     vector<string> s = getRightWord(a);
  78.     for (int i = 0; i < s.size(); i++)
  79.         cout << s[i] << ' ';
  80.  
  81.     fileIn.close();
  82.     fileIn.open("input.txt");
  83.     cout << endl << "____End of finded words___" << endl << "Original text:" << endl;
  84.     cout << a << endl;
  85.     cout << endl << "____End of original text___" << endl;
  86.  
  87.     system("pause");
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement