35657

Untitled

Jul 16th, 2023
948
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <string>
  6. #include <vector>
  7. #include <windows.h>  // для работы SetConsoleCP, SetConsoleOutputCP
  8.  
  9.  
  10. using namespace std;
  11.  
  12.  
  13. int main() {
  14.  
  15.     SetConsoleCP(1251); // установка кодовой страницы windows cp 1251 в поток ввода
  16.     SetConsoleOutputCP(1251); // установка кодовой страницы wincp 1251 в поток вывода
  17.  
  18.     ifstream fin;
  19.     fin.open("C:/Users/PC/Desktop/file.txt");
  20.  
  21.  
  22.     if (!fin.is_open()) {
  23.         cout << "Ошибка открытия файла" << endl;
  24.  
  25.     }
  26.     else {
  27.         int count = 0;
  28.         string word;
  29.         string user_word;
  30.         cout << "Введите слово для поиска: ";
  31.         getline(cin, user_word);
  32.         const int size = user_word.size();
  33.         int k = 0;
  34.         while (!fin.eof()) {
  35.             getline(fin, word);
  36.             for (int i = 0; i < word.size(); i++) {
  37.                 if (word[i] == user_word[0] ||  user_word[0] >= 'А' && user_word[0] < 'а' && word[i] == user_word[0] + 32 || user_word[0] >= 'а' && word[i] == user_word[0] - 32) { // вот здесь добавили проверок
  38.                     for (int j = 0; j < min(size, word.size()); j++) {
  39.                         if (word[i] == user_word[j] || user_word[j] >= 'А' && user_word[j] < 'а' && word[i] == user_word[j] + 32 || user_word[j] >= 'а' && word[i] == user_word[j] - 32) { // и здесь добавили проверок
  40.                             k++;
  41.                             i++;
  42.                         }
  43.                         else {
  44.                             k = 0;
  45.                             break;
  46.                         }
  47.                     }
  48.                     if (k == size) {
  49.                         count++;
  50.                     }
  51.                     k = 0;
  52.                 }
  53.             }
  54.         }
  55.         fin.close();
  56.         cout << count << " повторений" << endl;
  57.     }
  58. }
  59.  
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment