Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define forn(i, a, n) for(int i = a; i < n; ++i)
  3. #define pb push_back
  4.  
  5. #include <iostream>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <string>
  9. #include <stack>
  10. #include <set>
  11. #include <queue>
  12. #include <functional>
  13. #include <map>
  14.  
  15. using namespace std;
  16.  
  17. #pragma comment(linker, "/STACK:228228000")
  18.  
  19. //какая-то пиздец-структура, написанная михаилом
  20. typedef long long ll;
  21. struct VK
  22. {
  23. map<char, VK> childs;
  24. ll uses = 0, depth = 0;
  25.  
  26. void operator =(ll a)
  27. {
  28. depth = a;
  29. }
  30. void add(string& str)
  31. {
  32. if (str.size() == depth) return;
  33. char c = str[depth];
  34. childs[c] = depth + 1;
  35. childs[c].uses++;
  36. childs[c].add(str);
  37. }
  38.  
  39. ll check(string& str)
  40. {
  41. if (depth == str.size() && childs.size() > 0) return (-10e6);
  42. char c = str[depth];
  43. if (str.size() == depth) return (uses == 1);
  44. return (childs[c].check(str) + (uses == 1));
  45. }
  46. };
  47.  
  48.  
  49.  
  50.  
  51. bool norm(char c)
  52. {
  53. return(c >= 'a' && c <= 'z');
  54. }
  55.  
  56. int main() {
  57. freopen("input.txt", "r", stdin);
  58. freopen("output.txt", "w", stdout);
  59. int c = 0;
  60. string t, s;
  61. VK a;
  62.  
  63.  
  64. getline(cin, s);
  65. while (s.size() != 0)
  66. {
  67. t = "";
  68. int check = 0;
  69. while (!norm(s[check])) {
  70. check++;
  71. c++;
  72. }
  73. while (norm(s[check])) {
  74. t += s[check];
  75. check++;
  76. }
  77. while (check <= s.size()) // условие
  78. {
  79. if (check == s.size())
  80. check++;
  81.  
  82. int y = a.check(t);
  83. if (y < 0)
  84. c += t.size();
  85. else
  86. c += min(t.size() + 2 - a.check(t), (ll)t.size());
  87. a.add(t);
  88.  
  89.  
  90.  
  91. t = "";
  92. while (check < s.size() && !norm(s[check])) {
  93. check++;
  94. c++;
  95. }
  96. while (check < s.size() && norm(s[check])) {
  97. t += s[check];
  98. check++;
  99. }
  100. }
  101. getline(cin, s);
  102. c++;
  103. }
  104. cout << c;
  105. return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement