Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <conio.h>
- #include <string>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <queue>
- #include <set>
- using namespace std;
- string check(map<int, set<string>> dic, string word)
- {
- if (dic.find(word.size()) != dic.end())
- if (dic[word.size()].find(word) != dic[word.size()].end())
- return word;
- else
- {
- for (auto i = dic[word.size()].begin(); i != dic[word.size()].end(); i++)
- {
- int s = 0;
- string prom = *i;
- for (int j = 0; j <= i->size() - 1; j++)
- {
- if (word[j] != prom[j])
- s++;
- }
- if (s == 1)
- return prom;
- }
- }
- return word;
- }
- int main()
- {
- freopen("input.txt", "rt", stdin);
- freopen("output.txt", "wt", stdout);
- int n;
- string text;
- map<int, set<string>> dic;
- string prom;
- vector <string> answ;
- cin >> prom;
- while (prom != "#")
- {
- dic[prom.size()].insert(prom);
- cin >> prom;
- }
- int corr = 0;
- getline(cin, prom);
- while (getline(cin, prom))
- {
- string word;
- char lasts = 0;
- int last = 0;
- string line = "";
- for (int i = 0; i <= prom.size() - 1; i++)
- {
- if (prom[i] < 'a' || prom[i] > 'z')
- if (lasts >= 'a'&&lasts <= 'z')
- {
- word = prom.substr(last, i - last);
- string o = word;
- word = check(dic, word);
- if (o != word)
- corr++;
- line += word;
- line += prom[i];
- }
- else
- line += prom[i];
- else
- if (i == prom.size() - 1)
- {
- if (prom[i] == 13)
- {
- prom = "";
- break;
- }
- else
- {
- word = prom.substr(last, i - last + 1);
- string o = word;
- word = check(dic, word);
- if (o != word)
- corr++;
- line += word;
- }
- }
- else
- if (lasts < 'a' || lasts > 'z')
- last = i;
- lasts = prom[i];
- }
- answ.push_back(line);
- }
- for (auto i = answ.begin(); i != answ.end(); i++)
- {
- cout << *i << endl;
- }
- cout << corr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment