35657

Untitled

Jul 28th, 2023
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <map>
  7. #include <Windows.h>
  8. #include <fstream>
  9.  
  10. int main() {
  11.     SetConsoleCP(1251);
  12.     SetConsoleOutputCP(1251);
  13.  
  14.     std::ifstream fin("file.txt");
  15.  
  16.     if (!fin.is_open()) {
  17.         std::cout << "Ошибка открытия файла";
  18.     }
  19.     else {
  20.         std::string word;
  21.         std::map<std::string, int> dictionary;
  22.         while (!fin.eof()) {
  23.             fin >> word;
  24.             while (word.size() > 0 && (word[0] < 'А' || word[0] > 'я')) {
  25.                 word.erase(word.begin());
  26.             }
  27.             while (word.size() > 0 && (word.back() < 'А' || word.back() > 'я')) {
  28.                 word.pop_back();
  29.             }
  30.             if (word.size() > 0) {
  31.                 for (char& ch : word) {
  32.                     if (ch >= 'А' && ch <= 'Я') {
  33.                         ch += 32;
  34.                     }
  35.                 }
  36.                 dictionary[word]++;
  37.             }
  38.         }
  39.         for (auto a : dictionary) {
  40.             std::cout << a.first << " " << a.second << std::endl;
  41.         }
  42.         fin.close();
  43.     }
  44. }
  45.  
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment