Advertisement
georgiy110802

Untitled

Oct 8th, 2021
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int ans = 0;
  6.  
  7. struct node {
  8.     node *to[26] = {0};
  9.     bool terminal = false;
  10. };
  11.  
  12. node *root = new node();
  13.  
  14. void add(string &s) {
  15.     auto v = root;
  16.     for (auto c : s) {
  17.         c -= 'a';
  18.         if (!v->to[c])
  19.             v->to[c] = new node();
  20.         v = v->to[c];
  21.     }
  22.     if (!v->terminal)
  23.         ans++, v->terminal = true;
  24. }
  25.  
  26. int main() {
  27.     ios::sync_with_stdio(0);
  28.     cin.tie(0);
  29.     int n;
  30.     cin >> n;
  31.     while (n--) {
  32.         string s;
  33.         cin >> s;
  34.         add(s);
  35.     }
  36.     cout << ans;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement