放假第二天,猪排好像蛮好吃,尴尬的西餐,对面还是一个小姐姐,全程看JOJO缓解尬癌。
HDU 2846 Repository
复习加预习
#include <stdio.h> #include <string.h> #include <algorithm> #include <cmath> using namespace std; const int maxn = 650000; const int maxs = 21; char s[maxs]; int trie[maxn][26]; int tag[maxn]; int sum[maxn]; int tot = 1; void insert(char *s, int Tag) { int len = strlen(s), rt = 0, id; for (int i = 0; i < len; i++) { id = s[i] - 'a'; if (trie[rt][id] == 0) { trie[rt][id] = tot++; } rt = trie[rt][id]; if (tag[rt] != Tag) { tag[rt] = Tag; sum[rt]++; } } } int find(const char *s) { int len = strlen(s), rt = 0, id; for (int i = 0; i < len; i++) { id = s[i] - 'a'; if (trie[rt][id] == 0) return 0; rt = trie[rt][id]; // printf("rt = %d ", rt); } return sum[rt]; } int main () { int n, m; scanf("%d", &n); getchar(); for (int i = 1; i <= n; i++) { scanf("%s", s); getchar(); for (int j = 0; s[j]; j++) { insert(s+j, i); } } scanf("%d", &m); while (m--){ scanf("%s", s); printf("%d ", find(s)); } return 0; }