Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <fstream>
- #include <list>
- #include <locale>
- #include <Windows.h>
- #include <iterator>
- #include <sstream>
- #define і i
- using namespace std;
- int getRateWordByPattern(const string& word, const string& pattern) // пошук слова в словнику
- {
- int rate = 0;
- for (int i = 0; i < pattern.size(); ++i)
- rate += std::count(word.begin(), word.end(), pattern[i]);
- return rate;
- }
- list<string> GetListInFile(string path) {
- list<string> newListStr;
- ifstream ifs(path);
- list<string> words{ istream_iterator<string>(ifs), istream_iterator<string>() };
- for (auto word : words) {
- for (int i = 0; i < word.length(); i++)
- {
- if (word[i] == ',' || word[i] == '.' || word[i] == '!' || word[i] == '?')
- {
- word[i] = ' ';
- }
- }
- newListStr.push_back(word);
- }
- ifs.close();
- return newListStr;
- }
- void main()
- {
- setlocale(0, "");
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- string pattern = "прй hjuh\nf";
- string path = "dictionary.txt";
- string pathCheck = "text.txt";
- ifstream f;
- f.open(path);
- if (!f.is_open())
- return;
- int max_rate = 0;
- string res_word = "not found";
- list<string> l;
- string word, w;
- //while (f >> word)
- //{
- // int rate = getRateWordByPattern(word, pattern);
- // if (rate > max_rate)
- // {
- // max_rate = rate;
- // res_word = word;
- // }
- //}
- //String str;
- string s;
- while (getline(f, s))
- {
- //str.str
- //int rate = getRateWordByPattern(word, pattern);
- //if (max_rate != rate) {
- l.push_back(s);
- //}
- }
- f.close();
- for (auto word : GetListInFile(pathCheck)) {
- cout << word << endl;
- }
- for (auto item : l)
- {
- //cout << item << "\n";
- }
- //wcout << max_rate << endl;
- //cout << res_word << endl;
- //cout << w << endl;
- std::ofstream out("dictionary.txt", std::ios::ate);
- if (out.is_open())
- {
- out << "привіт\nуяви\nпрощавай gh, j" << std::endl;
- }
- out.close();
- std::string line;
- ifstream in("dictionary.txt"); // окрываем файл для чтения
- if (in.is_open())
- {
- while (getline(in, line))
- {
- //std::cout << line << std::endl;
- }
- }
- string ls;
- while (in >> line)
- {
- if (line == " ") {
- line += "\n";
- }
- //l.push_back((line));
- }
- for (auto item : l)
- {
- //cout << item << "\n";
- }
- in.close();
- string res;
- list<string> lres;
- for (auto item : l)
- {
- res += item + " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment