Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <cstdio>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. const int MAX = 1e6 + 100;
  10.  
  11. bool isletter(char c) {
  12. if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
  13. return true;
  14. }
  15. return false;
  16. }
  17.  
  18. struct vertex {
  19. bool leaf;
  20. int next[27 * 2 + 10];
  21. long long count = 0;
  22. int id = 0;
  23. };
  24.  
  25. vertex bor[MAX + 1];
  26. int numb;
  27. char make_char(int n) {
  28. cerr << "&&&&&&&&" << n << endl;
  29. if (n < 27) {
  30. int a = 'A' + n;
  31. return (char) a;
  32. } else {
  33. int a = 'a' - 27 + n;
  34. cerr << a << endl;
  35. return (char) a;
  36. }
  37. }
  38.  
  39. void dfs(int v, string &s) {
  40. const int alph = 52;
  41. cerr << "YES" << '\n';
  42. if (bor[v].leaf) {
  43. cout << s << ';' << bor[v].count << ';' << bor[v].id << endl;
  44. }
  45. for (size_t i = 0; i < alph; ++i) {
  46. if (bor[v].next[i] != -1 ) {
  47. char c = make_char(i);
  48. cout << "********" << c << endl;
  49. s += c;
  50. dfs(bor[v].next[i], s);
  51. }
  52. }
  53. }
  54.  
  55. void add (string &id, int count, string &country) {
  56. int v = 0;
  57. for (size_t i = 0; i < country.size(); ++i) {
  58. unsigned char c;
  59. if (isupper(country[i])) {
  60. c = country[i] - 'A';
  61. } else {
  62. c = country[i] - 'a' + 27;
  63. }
  64. if (bor[v].next[c] == -1) {
  65. cout << "fibhseuidwl";
  66. memset (bor[numb].next, 255, sizeof(bor[numb].next));
  67. bor[v].next[c] = numb++;
  68. }
  69. v = bor[v].next[c];
  70. }
  71. bor[v].count += count;
  72. bor[v].leaf = true;
  73. int v_term = v;
  74. bool check_new = false;
  75. for (size_t i = 0; i < id.size(); ++i) {
  76. char c = id[i] - '0' + 27 * 2;
  77. if (bor[v].next[c] == -1) {
  78. memset (bor[numb].next, 255, sizeof(bor[numb].next));
  79. bor[v].next[c] = numb++;
  80. check_new = 1;
  81. }
  82. v = bor[v].next[c];
  83. }
  84. bor[v].leaf = true;
  85. if (check_new) {
  86. bor[v_term].id++;
  87. }
  88. }
  89.  
  90. int main() {
  91. //ifstream fin ("input.txt");
  92. freopen("input.txt", "rt", stdin);
  93.  
  94. string s;
  95. //cin >> s;
  96. //cout << s;
  97. while (cin >> s) {
  98. cout << "nbdjqw";
  99. string id = "";
  100. string count = "";
  101. string country = "";
  102. size_t ind = 0;
  103. bool check_format = true;
  104. for (;ind < s.size(); ++ind) {
  105. if (isdigit(s[ind])) {
  106. id += s[ind];
  107. } else {
  108. if (s[ind] != ';') {
  109. check_format = false;
  110. }
  111. break;
  112. }
  113. }
  114. ++ind;
  115. for (;ind < s.size(); ++ind) {
  116. if (isdigit(s[ind])) {
  117. count += s[ind];
  118. } else {
  119. if (s[ind] != ';') {
  120. check_format = false;
  121. }
  122. break;
  123. }
  124. }
  125. ++ind;
  126. for (;ind < s.size(); ++ind) {
  127. if (isletter(s[ind])) {
  128. country += s[ind];
  129. } else {
  130. if (s[ind] != ';') {
  131. check_format = false;
  132. }
  133. break;
  134. }
  135. }
  136. if (!check_format) {
  137. continue;
  138. }
  139. int count1 = stoi(count);
  140. memset (bor[0].next, 255, sizeof bor[0].next);
  141. numb = 1;
  142. add(id, count1, country);
  143. }
  144. s = "";
  145. cout << numb;
  146. for (int i = 0; i < numb; i++) {
  147. for (int j = 0; j < 64; j++) {
  148. cout << bor[i].next[j] << " ";
  149. }
  150. cout << '\n';
  151. }
  152. dfs(0, s);
  153.  
  154. return 0;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement