Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <set>
  5. #include <deque>
  6. #include <stack>
  7. #include <bitset>
  8. #include <algorithm>
  9. #include <functional>
  10. #include <numeric>
  11. #include <utility>
  12. #include <sstream>
  13. #include <iostream>
  14. #include <fstream>
  15. #include <string.h>
  16. #include <iomanip>
  17. #include <cstdio>
  18. #include <cmath>
  19. #include <cstdlib>
  20. #include <ctime>
  21. #include <queue>
  22. #define inf 1000*1000*1000
  23. #define mod 1000000007
  24. #define ff first
  25. #define ss second
  26. #define mp make_pair
  27. using namespace std;
  28. struct vertex {
  29. int next[309];
  30. bool leaf;
  31. };
  32.  
  33. vertex t[300009];
  34. int sz, ind, ans, start = -1;
  35. char c[300009];
  36. void add_string (const string & s) {
  37. int v = 0;
  38. for (size_t i=0; i<s.length(); ++i) {
  39. char c = s[i]-'a';
  40. if (t[v].next[c] == -1) {
  41. memset (t[sz].next, 255, sizeof t[sz].next);
  42. t[v].next[c] = sz++;
  43. }
  44. v = t[v].next[c];
  45. }
  46. t[v].leaf = true;
  47. }
  48. void print_tree(int v) {
  49. for(int i = 0; i<=25; i++) {
  50. if(t[v].next[i] != -1) {
  51. cout<<char(i+'a')<<" "<<t[v].leaf<<endl;
  52. print_tree(t[v].next[i]);
  53. }
  54. }
  55. }
  56.  
  57. string in;
  58. int main() {
  59. memset (t[0].next, 255, sizeof t[0].next);
  60. sz = 1;
  61. while(getline(cin,in)) {
  62. start = -1;
  63. cout<<in<<endl;
  64. for(int i=0;i<in.length();i++)
  65. {
  66. c[ind] = in[i];
  67. ind++;
  68. }
  69. for (int i=0;i<in.length();i++) {
  70. if((in[i]-'a'>=0 && in[i]-'a'<=25)) {
  71. start = i;
  72. break;
  73. }
  74. }
  75. if(start != -1) {
  76. for (int i=start;i<in.length();i++) {
  77. if(!(in[i]-'a'>=0 && in[i]-'a'<=25) || (in[i] == '\n')) {
  78. ans++;
  79. string cur = "";
  80. for(int j = start; j < i; j++)
  81. cur += c[j];
  82. //cout<<cur<<endl;
  83. add_string(cur);
  84. start = i + 1;
  85. }
  86. }
  87. }
  88. }
  89. print_tree(0);
  90. cout<<in<<endl;
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement