Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int ans = 0;
- struct node {
- node *to[26] = {0};
- bool terminal = false;
- };
- node *root = new node();
- void add(string &s) {
- auto v = root;
- for (auto c : s) {
- c -= 'a';
- if (!v->to[c])
- v->to[c] = new node();
- v = v->to[c];
- }
- if (!v->terminal)
- ans++, v->terminal = true;
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- int n;
- cin >> n;
- while (n--) {
- string s;
- cin >> s;
- add(s);
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement