-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtelephone-numbers.cpp
More file actions
47 lines (39 loc) · 820 Bytes
/
telephone-numbers.cpp
File metadata and controls
47 lines (39 loc) · 820 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
47
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
struct Node {
map<int, Node*> children;
};
Node* head;
int cmpt = 0;
void addTel(string telephone)
{
auto node = head;
for(auto i = 0; i < telephone.size(); ++i)
{
int number = telephone.at(i) + '0';
auto it = node->children.find(number);
if(it == node->children.end())
{
node->children[number] = new Node{};
cmpt++;
}
node = node->children[number];
}
}
int main()
{
int N;
cin >> N; cin.ignore();
head = new Node{};
for (int i = 0; i < N; i++)
{
string telephone;
cin >> telephone; cin.ignore();
addTel(telephone);
}
cout << cmpt << endl;
}