Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 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 f first
  4. #define s second
  5. #define pb push_back
  6. #define mp make_pair
  7.  
  8. #include <iostream>
  9. #include <vector>
  10. #include <algorithm>
  11. #include <string>
  12. #include <stack>
  13. #include <set>
  14. #include <queue>
  15. #include <functional>
  16. #include <map>
  17.  
  18. //#pragma comment(linker, "/STACK:6777237" )
  19.  
  20. using namespace std;
  21. typedef long long ll;
  22. typedef long double ld;
  23.  
  24. ll lastb = 0;
  25.  
  26. struct boar
  27. {
  28. ll pos = 0;
  29. map<char, boar> chi;
  30.  
  31. void operator = (ll a)
  32. {
  33. pos = a;
  34. }
  35.  
  36. ll finder(string& word) // left, right
  37. {
  38. ll result = 0;
  39. char c = word[pos];
  40. if (word.size() == pos && chi.size() == 0) return 0;
  41. if (word.size() == pos && chi.size() > 0) return 2;
  42. if (chi[c].pos == 0)
  43. {
  44. result = 1;
  45. chi[c] = pos + 1;
  46. }
  47. return max((chi[c].finder(word)), result);
  48. }
  49.  
  50. };
  51.  
  52.  
  53.  
  54. string s;
  55. ll cursor, outp;
  56. boar dict;
  57. map<string, ll> stash;
  58.  
  59.  
  60. bool norm(char c)
  61. {
  62. return(c >= 'a' && c <= 'z');
  63. }
  64.  
  65.  
  66. string cut()
  67. {
  68. string res;
  69. while (cursor < s.size() && !norm(s[cursor]))
  70. {
  71. cursor++;
  72. outp++;
  73. }
  74. while (cursor < s.size() && norm(s[cursor]))
  75. {
  76. res += s[cursor];
  77. cursor++;
  78. }
  79. while (cursor < s.size() && !norm(s[cursor]))
  80. {
  81. cursor++;
  82. outp++;
  83. }
  84. return res;
  85. }
  86.  
  87. void counter()
  88. {
  89. while (cursor < s.size())
  90. {
  91. string work = cut();
  92. ll b = dict.finder(work);
  93. string pat = "";
  94. outp += work.size();
  95. //if(work.size())
  96. ll pus = 2;
  97. forn(i, 0, work.size())
  98. {
  99. pat += work[i];
  100. if (b == 2)
  101. {
  102. stash[pat]++;
  103. }
  104.  
  105. if (stash[pat] == 1)
  106. {
  107. pus--;
  108. }
  109.  
  110. if (b == 1)
  111. {
  112. stash[pat]++;
  113. }
  114. }
  115. outp += min(pus, (ll)0);
  116. }
  117. }
  118.  
  119.  
  120. int main(void) {
  121. #ifndef ONLINE_JUDGE
  122. freopen("input.txt", "r", stdin);
  123. freopen("output.txt", "w", stdout);
  124. #endif
  125.  
  126. getline(cin, s);
  127. while (s.size() != 0)
  128. {
  129. outp++;
  130. cursor = 0;
  131. counter();
  132. s.clear();
  133. getline(cin, s);
  134. }
  135.  
  136. cout << outp;
  137.  
  138. return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement