-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbing.cc
More file actions
46 lines (35 loc) · 888 Bytes
/
bing.cc
File metadata and controls
46 lines (35 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* William Sjöblom
* Some kind of trie where each node is labeled how many words that got here.
*/
#include <map>
#include <iostream>
#include <string>
#include <cmath>
/**
* Trie node thingy.
*/
struct Node {
std::map<char, Node*> transitions;
int count;
};
int main() {
int word_count; scanf("%d", &word_count);
Node* root = new Node();
root->count = 0;
while (word_count--) {
std::string word; std::cin >> word;
Node* node = root;
for (char c : word) {
if (node->transitions.count(c)) {
node = node->transitions[c];
} else {
Node* added = new Node();
node->transitions[c] = added;
node = added;
}
node->count++;
}
std::cout << node->count - 1 << std::endl;
}
}