Guest User

Untitled

a guest
May 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define ld long double
  5. #define prec(k) fixed << setprecision(k)
  6. #define up(i, k, n) for (int i = k ; i < n ; i ++)
  7. #define down(i, k, n) for (int i = k ; i >= n ; i --)
  8. #define ii pair<int, int>
  9. #define pll pair <ll, ll>
  10. #define X first
  11. #define Y second
  12. #define str basic_string <int>
  13. const int maxN = (int) 1e4 + 7;
  14. const int maxM = (int) 1e5 + 7;
  15. const int maxT = (int) 3e6 + 7;
  16.  
  17. using namespace std;
  18.  
  19. static int n, a[maxT], b[maxT][26], node, q;
  20. static bool isEnd[maxT];
  21.  
  22. void ins(string &s)
  23. {
  24. int root = 0;
  25. for (auto i : s)
  26. if (b[root][i] == 0)
  27. {
  28. node ++;
  29. a[node] = i;
  30. root = b[root][i] = node;
  31. }
  32. else root = b[root][i];
  33. isEnd[root] = true;
  34. }
  35.  
  36. bool Find(string &s)
  37. {
  38. int root = 0;
  39. for (auto i : s)
  40. if (b[root][i] != 0) root = b[root][i];
  41. else return false;
  42. return isEnd[root];
  43. }
  44.  
  45. void solve()
  46. {
  47. cin >> q;
  48. while (q --)
  49. {
  50. string p;
  51. cin >> p;
  52. cout << (Find(p) ? "In\n" : "Out\n");
  53. }
  54. }
  55.  
  56. void enter()
  57. {
  58. cin >> n;
  59. up(i, 0, n)
  60. {
  61. string s;
  62. cin >> s;
  63. ins(s);
  64. }
  65. }
  66.  
  67. int main()
  68. {
  69. ios_base::sync_with_stdio(false);
  70. cin.tie(nullptr);
  71.  
  72. enter();
  73. cout << node + 1;
  74. //solve();
  75.  
  76. return 0;
  77. }
Add Comment
Please, Sign In to add comment