-
Notifications
You must be signed in to change notification settings - Fork 1
/
ADAINDEX - Ada and Indexing.cc
56 lines (54 loc) · 1.2 KB
/
ADAINDEX - Ada and Indexing.cc
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
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
struct Map {
int children;
map<char, Map*> cmap;
Map() {
children = 0;
}
};
int main() {
int N, M;
char c;
Map *temp, *root, *curr;
root = new Map();
map<char, Map*>::iterator it;
scanf("%d %d", &N, &M);
getchar();
for (int i = 0; i < N; i++) {
curr = root;
c = getchar();
while (c != '\n') {
it = curr->cmap.find(c);
if (it == curr->cmap.end()) {
temp = new Map();
curr->cmap.insert(pair<char, Map*>(c, temp));
curr = temp;
}//if
else
curr = it->second;
curr->children++;
c = getchar();
}//while
}//for
for (int i = 0; i < M; i++) {
curr = root;
c = getchar();
while (c != '\n') {
it = curr->cmap.find(c);
if (it == curr->cmap.end()) {
printf("0\n");
while (c != '\n') {
c = getchar();
}
break;
}//if
else
curr = it->second;
c = getchar();
}//while
if (it != curr->cmap.end())
printf("%d\n", it->second->children);
}//for
return 0;
}//main