Vla_DOS

Untitled

Sep 6th, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.16 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] == '?' || 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, newStr;
  64.  
  65.     while (f >> word)
  66.     {
  67.  
  68.         for (auto w : GetListInFile(pathCheck))
  69.         {
  70.             max_rate = 0;
  71.             int rate = getRateWordByPattern(word, w);
  72.             if (rate > max_rate)
  73.             {
  74.                 max_rate = rate;
  75.                 res_word = word;
  76.             }
  77.         }
  78.         cout << max_rate << endl;
  79.         cout << res_word << endl;
  80.     }
  81.     cout << newStr << endl;
  82.     cout << max_rate << endl;
  83.     cout << res_word << endl;
  84.     cout << w << endl;  
  85.  
  86.     string s;
  87.     while (getline(f, s))
  88.     {
  89.         //str.str
  90.         //int rate = getRateWordByPattern(word, pattern);
  91.  
  92.         //if (max_rate != rate) {
  93.            l.push_back(s);
  94.         //}
  95.     }
  96.  
  97.     f.close();
  98.  
  99.     for (auto word : GetListInFile(pathCheck)) {
  100.          //cout << word << endl;
  101.     }
  102.  
  103.  
  104.     for (auto item : l)
  105.     {
  106.         //cout << item << "\n";
  107.     }
  108.  
  109.     //std::ofstream out("dictionary.txt", std::ios::app);
  110.     //if (out.is_open())
  111.     //{
  112.     //    //out << "привіт\nуяви\nпрощавай gh, j" << std::endl;
  113.     //}
  114.     //out.close();
  115.     //std::string line;
  116.  
  117.     //ifstream in("dictionary.txt"); // окрываем файл для чтения
  118.     //if (in.is_open())
  119.     //{
  120.     //    while (getline(in, line))
  121.     //    {
  122.     //        //std::cout << line << std::endl;
  123.     //    }
  124.     //}
  125.     //string ls;
  126.     //while (in >> line)
  127.     //{
  128.     //    if (line == " ") {
  129.     //        line += "\n";
  130.     //    }
  131.     //    
  132.     //        //l.push_back((line));
  133.     //}
  134.     //for (auto item : l)
  135.     //{
  136.     //    //cout << item << "\n";
  137.     //}
  138.  
  139.     //in.close();  
  140.     string res;
  141.     list<string> lres;
  142.     for (auto item : l)
  143.     {
  144.         res += item + " ";
  145.     }
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment