Vla_DOS

Untitled

Sep 5th, 2022
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <fstream>
  5. #include <list>
  6. #include <locale>
  7. #include <Windows.h>
  8. #include <iterator>
  9. #include <sstream>
  10.  
  11. #define і i
  12.  
  13. using namespace std;
  14.  
  15. int getRateWordByPattern(const string& word, const string& pattern) // пошук слова в словнику
  16. {
  17.     int rate = 0;
  18.  
  19.     for (int i = 0; i < pattern.size(); ++i)
  20.         rate += std::count(word.begin(), word.end(), pattern[i]);
  21.  
  22.     return rate;
  23. }
  24.  
  25. list<string> GetListInFile(string path) {
  26.     list<string> newListStr;
  27.     ifstream ifs(path);
  28.     list<string> words{ istream_iterator<string>(ifs), istream_iterator<string>() };
  29.  
  30.     for (auto word : words) {
  31.  
  32.         for (int i = 0; i < word.length(); i++)
  33.         {
  34.             if (word[i] == ',' || word[i] == '.' || word[i] == '!' || word[i] == '?')
  35.             {
  36.                 word[i] = ' ';
  37.             }
  38.         }
  39.         newListStr.push_back(word);
  40.     }
  41.     ifs.close();
  42.  
  43.     return newListStr;
  44. }
  45.  
  46. void main()
  47. {
  48.     setlocale(0, "");
  49.     SetConsoleCP(1251);
  50.     SetConsoleOutputCP(1251);
  51.     string pattern = "прй hjuh\nf";
  52.     string path = "dictionary.txt";
  53.     string pathCheck = "text.txt";
  54.     ifstream f;
  55.     f.open(path);
  56.  
  57.     if (!f.is_open())
  58.         return;
  59.  
  60.     int max_rate = 0;
  61.     string res_word = "not found";
  62.     list<string> l;
  63.     string word, w;
  64.     //while (f >> word)
  65.     //{
  66.     //    int rate = getRateWordByPattern(word, pattern);
  67.     //    if (rate > max_rate)
  68.     //    {
  69.     //        max_rate = rate;
  70.     //        res_word = word;
  71.     //    }
  72.  
  73.     //}
  74.     //String str;
  75.     string s;
  76.     while (getline(f, s))
  77.     {
  78.         //str.str
  79.         //int rate = getRateWordByPattern(word, pattern);
  80.  
  81.         //if (max_rate != rate) {
  82.            l.push_back(s);
  83.         //}
  84.     }
  85.  
  86.     f.close();
  87.  
  88.     for (auto word : GetListInFile(pathCheck)) {
  89.          cout << word << endl;
  90.     }
  91.  
  92.  
  93.     for (auto item : l)
  94.     {
  95.         //cout << item << "\n";
  96.     }
  97.     //wcout << max_rate << endl;
  98.     //cout << res_word << endl;
  99.     //cout << w << endl;
  100.     std::ofstream out("dictionary.txt", std::ios::ate);
  101.     if (out.is_open())
  102.     {
  103.         out << "привіт\nуяви\nпрощавай gh, j" << std::endl;
  104.     }
  105.     out.close();
  106.     std::string line;
  107.  
  108.     ifstream in("dictionary.txt"); // окрываем файл для чтения
  109.     if (in.is_open())
  110.     {
  111.         while (getline(in, line))
  112.         {
  113.             //std::cout << line << std::endl;
  114.         }
  115.     }
  116.     string ls;
  117.     while (in >> line)
  118.     {
  119.         if (line == " ") {
  120.             line += "\n";
  121.         }
  122.        
  123.             //l.push_back((line));
  124.     }
  125.     for (auto item : l)
  126.     {
  127.         //cout << item << "\n";
  128.     }
  129.  
  130.     in.close();  
  131.     string res;
  132.     list<string> lres;
  133.     for (auto item : l)
  134.     {
  135.         res += item + " ";
  136.     }
  137.  
  138. }
Advertisement
Add Comment
Please, Sign In to add comment