voidInsert(char *word){ int len = strlen(word); int root = 0; for (int i = 0; i < len; i++) { int id = word[i] - '0'; if (!tree[root][id]) tree[root][id] = ++tot; root = tree[root][id]; flagg[root]++; } //flagg[root] += 1; }
intFind(char* word){ int len = strlen(word); int root = 0; int ans = 0; for (int i = 0; i < len; i++) { int id = word[i] - '0'; if (!tree[root][id]) return0; //if (flagg[tree[root][id]]) //ans += 1; root = tree[root][id]; } ans = flagg[root]; return ans; }
voidinit(){ for (int i = 0; i <= tot; i++) { flagg[i] = false; for (int j = 0; j < 30; j++) { tree[i][j] = 0; } } tot = 0; }
intmain(){ char word[11]; int n, m; init(); while (cin.getline(word, 12)) { if (strlen(word) == 0) { break; } Insert(word); } while (scanf("%s", word) != EOF) { printf("%d\n", Find(word)); } return0; }