35657

Untitled

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