Advertisement
Ne-Biolog

Untitled

Mar 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <memory.h>
  4. #include <iterator>
  5. #include <cassert>
  6. #include <fstream>
  7. #include <iomanip>
  8. #include <cstdlib>
  9. #include <bitset>
  10. #include <vector>
  11. #include <cstdio>
  12. #include <string>
  13. #include <queue>
  14. #include <deque>
  15. #include <cmath>
  16. #include <ctime>
  17. #include <stack>
  18. #include <set>
  19. #include <map>
  20.  
  21. using namespace std;
  22.  
  23. //#define int long long
  24.  
  25. #define fi first
  26. #define se second
  27. #define pb push_back
  28. #define mp make_pair
  29. #define all(x) x.begin() , x.end()
  30.  
  31. typedef long long ll;
  32. typedef long double ld;
  33. typedef pair < ll , ll > pll;
  34. typedef pair < int , int > pii;
  35.  
  36. template < typename T >
  37. T read(){
  38. T p = 1 , x = 0;
  39. char s = getchar();
  40. while(s == ' ' || s == '\n') s = getchar();
  41. if(s == '-') p = -1 , s = getchar();
  42. while(s >= '0' && s <= '9'){
  43. x = x * 10 + s - '0';
  44. s = getchar();
  45. }
  46. return x * p;
  47. }
  48.  
  49. template < typename A , typename B >
  50. void Umax(A &a , const B &b){
  51. if(a < b)
  52. a = b;
  53. }
  54.  
  55. template < typename A , typename B >
  56. void Umin(A &a , const B &b){
  57. if(a > b){
  58. a = b;
  59. }
  60. }
  61.  
  62. ll bin_pow (ll a , ll n) {
  63. if(n == 0){
  64. return 1;
  65. }
  66. if(n % 2 == 1){
  67. ll cnt = a * bin_pow(a , n - 1);
  68. return cnt;
  69. }
  70. else {
  71. ll cnt = bin_pow(a , n / 2);
  72. return cnt * cnt;
  73. }
  74. }
  75.  
  76. const int N = (int) 1e5 + 10;
  77. const int MOD = (int) 1e9 + 7;
  78. const int INF = (int) 1e9 + 10;
  79. const ll LLINF = (ll) 1e18 + 10;
  80. const int dx [] = { 0 , 0 , 1 , -1 };
  81. const int dy [] = { 1 , -1 , 0 , 0 };
  82.  
  83.  
  84. ll ans = 0, cnt = 1;
  85. vector <string> s;
  86. pair <int, int > trie[3 * N][26];
  87.  
  88. void add(string val) {
  89. int v = 1;
  90. for(int i = 0; i < val.size(); ++i) {
  91. int f = static_cast<int>(val[i]) - 97;
  92. if(trie[v][f].fi == 0) {
  93. trie[v][f].fi = ++cnt;
  94. trie[v][f].se++;
  95. } else {
  96. trie[v][f].se++;
  97. }
  98. v = trie[v][f].fi;
  99. }
  100. }
  101.  
  102. void get(string val) {
  103. int v = 1;
  104. for(int i = 0; i < val.size(); ++i) {
  105. int f = static_cast<int>(val[i]) - 97;
  106. if(trie[v][f].se > 1) {
  107. cout << val[i];
  108. ans++;
  109. } else {
  110. cout << val[i];
  111. ans++;
  112. return;
  113. }
  114. v = trie[v][f].fi;
  115. }
  116. }
  117.  
  118. int main ()
  119. {
  120. freopen("input.txt" , "r" , stdin);
  121. freopen("output.txt" , "w" , stdout);
  122. ios_base::sync_with_stdio(false);
  123.  
  124. char ch;
  125. string currS= "";
  126. while((ch = getchar()) != EOF) {
  127. if(ch >= 'a' && ch <= 'z') {
  128. currS += ch;
  129. } else {
  130. if(currS.size() > 0) {
  131. s.pb(currS);
  132. add(currS);
  133. currS = "";
  134. }
  135. ans++;
  136. }
  137. }
  138.  
  139. for(int i = 0; i < s.size(); ++i) {
  140. get(s[i]);
  141. cout << endl;
  142. }
  143.  
  144. cout << ans << endl;
  145.  
  146.  
  147. return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement