Advertisement
artemgf

Тараканы!

Nov 30th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.79 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <string>
  4. #include <map>
  5. #include <set>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <stdio.h>
  9. #include <cmath>
  10. #include <math.h>
  11. #include <queue>
  12. #include <stack>
  13. #include <climits>
  14. #include <deque>
  15. #include <ctime>
  16.  
  17. using namespace std;
  18.  
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21. typedef unsigned int ui;
  22.  
  23. #define mh() make_heap()
  24. #define poph() pop_heap()
  25. #define pushh() push_heap()
  26. #define sor(n) n.begin(), n.end()
  27. #define mp make_pair
  28. #define files freopen("vampire.in", "rt", stdin); freopen("vampire.out", "wt", stdout)
  29.  
  30. #define formx(a1,b1,c1,a2,b2,c2) ((a1*c2-a2*c1)/(a1*b2-b1*a2))
  31. #define formy(a1,b1,c1,a2,b2,c2) ((c1*b2-c2*b1)/(a1*b2-b1*a2))
  32. #define forma(y1,y2) (y2-y1)
  33. #define formb(x1,x2) (x1-x2)
  34. #define formc(x1,y1,x2,y2) (x1*(y2-y1)-y1*(x2-x1))
  35. #define ras(x1,y1,x2,y2) sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
  36.  
  37. struct cord
  38. {
  39.     double x1, y1, x2, y2;
  40. };
  41. struct limcord
  42. {
  43.     double x, y;
  44.     bool good;
  45. };
  46.  
  47. bool checkparal(double a1, double a2, double b1, double b2)
  48. {
  49.     return a1 / b1 == a2 / b2;
  50. }
  51.  
  52. limcord findt(cord c, cord now)
  53. {
  54.     double a1 = forma(now.y1, now.y2);
  55.     double b1 = formb(now.x1, now.x2);
  56.     double c1 = formc(now.x1, now.y1, now.x2, now.y2);
  57.     double a2 = forma(c.y1, c.y2);
  58.     double b2 = formb(c.x1, c.x2);
  59.     double c2 = formc(c.x1, c.y1, c.x2, c.y2);
  60.  
  61.     if (!checkparal(a1, a2, b1, b2))
  62.     {
  63.         double x = formx(a1, b1, c1, a2, b2, c2);
  64.         double y = formy(a1, b1, c1, a2, b2, c2);
  65.         return{ x,y, true };
  66.     }
  67.     else
  68.     {
  69.         return{ NULL,NULL, false };
  70.     }
  71. }
  72.  
  73. bool checkT(limcord now, cord ot)
  74. {
  75.     if (ras(ot.x1, ot.y1, ot.x2, ot.y2) == ras(ot.x1, ot.y1, now.x, now.y) + ras(ot.x2, ot.y2, now.x, now.y))
  76.         return true;
  77.     else
  78.         return false;
  79. }
  80.  
  81. string check(map<int, set<string>> dic, string word)
  82. {
  83.     if (dic.find(word.size()) != dic.end())
  84.         if (dic[word.size()].find(word) != dic[word.size()].end())
  85.             return word;
  86.         else
  87.         {
  88.             for (auto i = dic[word.size()].begin(); i != dic[word.size()].end(); i++)
  89.             {
  90.                 int s = 0;
  91.                 string prom = *i;
  92.                 for (int j = 0; j <= i->size() - 1; j++)
  93.                 {
  94.                     if (word[j] != prom[j])
  95.                         s++;
  96.                 }
  97.                 if (s == 1)
  98.                     return prom;
  99.             }
  100.         }
  101.     return word;
  102. }
  103.  
  104. int main()
  105. {
  106.     //files;
  107.     /*int n;
  108.     string text;
  109.     map<int, set<string>> dic;
  110.     string prom;
  111.     vector <string> answ;
  112.  
  113.     cin >> prom;
  114.     while (prom != "#")
  115.     {
  116.         dic[prom.size()].insert(prom);
  117.         cin >> prom;
  118.     }
  119.     int corr = 0;
  120.     getline(cin, prom);
  121.     while (getline(cin, prom))
  122.     {
  123.         string word;
  124.         char lasts = 0;
  125.         int last = 0;
  126.         string line = "";
  127.         for (int i = 0; i <= prom.size() - 1; i++)
  128.         {
  129.             if (prom[i] < 'a' || prom[i] > 'z')
  130.                 if (lasts >= 'a'&&lasts <= 'z')
  131.                 {
  132.                     word = prom.substr(last, i - last);
  133.                     string o = word;
  134.                     word = check(dic, word);
  135.                     if (o != word)
  136.                         corr++;
  137.                     line += word;
  138.                     line += prom[i];
  139.                 }
  140.                 else
  141.                     line += prom[i];
  142.             else
  143.                 if (i == prom.size() - 1)
  144.                 {
  145.                     if (prom[i] == 13)
  146.                     {
  147.                         prom = "";
  148.                         break;
  149.                     }
  150.                     else
  151.                     {
  152.                         word = prom.substr(last, i - last + 1);
  153.                         string o = word;
  154.                         word = check(dic, word);
  155.                         if (o != word)
  156.                             corr++;
  157.                         line += word;
  158.                     }
  159.                 }
  160.                 else
  161.                     if (lasts < 'a' || lasts > 'z')
  162.                         last = i;
  163.             lasts = prom[i];
  164.         }
  165.         answ.push_back(line);
  166.     }
  167.  
  168.     for (auto i = answ.begin(); i != answ.end(); i++)
  169.     {
  170.         cout << *i << endl;
  171.     }
  172.     cout << corr;*/
  173.    
  174.     set<string> room;
  175.     string s;
  176.     cin >> s;
  177.     room.insert(s);
  178.     cin >> s;
  179.     while (s != "#")
  180.     {
  181.         for (int i = 0; i < s.size(); i++)
  182.         {
  183.             if (s[i] == '-')
  184.             {
  185.                 room.insert(s.substr(0, i));
  186.                 room.insert(s.substr(i+1, s.size()-i-1));
  187.             }
  188.         }
  189.         cin >> s;
  190.     }
  191.  
  192.     cout << room.size() - 1;
  193.     system("pause");
  194.     return 0;
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement