artemgf

Проверка со словарём

Oct 28th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <string>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <map>
  8. #include <queue>
  9. #include <set>
  10. using namespace std;
  11.  
  12. string check(map<int, set<string>> dic, string word)
  13. {
  14.     if (dic.find(word.size()) != dic.end())
  15.         if (dic[word.size()].find(word) != dic[word.size()].end())
  16.             return word;
  17.         else
  18.         {
  19.             for (auto i = dic[word.size()].begin(); i != dic[word.size()].end(); i++)
  20.             {
  21.                 int s = 0;
  22.                 string prom = *i;
  23.                 for (int j = 0; j <= i->size() - 1; j++)
  24.                 {
  25.                     if (word[j] != prom[j])
  26.                         s++;
  27.                 }
  28.                 if (s == 1)
  29.                     return prom;
  30.             }
  31.         }
  32.     return word;
  33. }
  34. int main()
  35. {
  36.     freopen("input.txt", "rt", stdin);
  37.     freopen("output.txt", "wt", stdout);
  38.     int n;
  39.     string text;
  40.     map<int, set<string>> dic;
  41.     string prom;
  42.     vector <string> answ;
  43.  
  44.     cin >> prom;
  45.     while (prom != "#")
  46.     {
  47.         dic[prom.size()].insert(prom);
  48.         cin >> prom;
  49.     }
  50.     int corr = 0;
  51.     getline(cin, prom);
  52.     while (getline(cin, prom))
  53.     {
  54.         string word;
  55.         char lasts = 0;
  56.         int last = 0;
  57.         string line = "";
  58.         for (int i = 0; i <= prom.size() - 1; i++)
  59.         {
  60.             if (prom[i] < 'a' || prom[i] > 'z')
  61.                 if (lasts >= 'a'&&lasts <= 'z')
  62.                 {
  63.                     word = prom.substr(last, i - last);
  64.                     string o = word;
  65.                     word = check(dic, word);
  66.                     if (o != word)
  67.                         corr++;
  68.                     line += word;
  69.                     line += prom[i];
  70.                 }
  71.                 else
  72.                     line += prom[i];
  73.             else
  74.                 if (i == prom.size() - 1)
  75.                 {
  76.                     if (prom[i] == 13)
  77.                     {
  78.                         prom = "";
  79.                         break;
  80.                     }
  81.                     else
  82.                     {
  83.                         word = prom.substr(last, i - last + 1);
  84.                         string o = word;
  85.                         word = check(dic, word);
  86.                         if (o != word)
  87.                             corr++;
  88.                         line += word;
  89.                     }
  90.                 }
  91.                 else
  92.                     if (lasts < 'a' || lasts > 'z')
  93.                         last = i;
  94.             lasts = prom[i];
  95.         }
  96.         answ.push_back(line);
  97.     }
  98.  
  99.     for (auto i = answ.begin(); i != answ.end(); i++)
  100.     {
  101.         cout << *i << endl;
  102.     }
  103.     cout << corr;
  104.  
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment