标签:span 思路 nan define 前缀 pid 单词 auth limit
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
Total Submission(s): 43840 Accepted Submission(s): 15713
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define MAXN 400001 using namespace std; char s[11]; bool p; int root,tot,len,sum[MAXN],trie[MAXN][27]; void insert(){ len=strlen(s); root=0; for(int i=0;i<len;i++){ int x=s[i]-‘a‘; if(!trie[root][x]) trie[root][x]=++tot; sum[trie[root][x]]++; root=trie[root][x]; } } int find(){ root=0; len=strlen(s); for(int i=0;i<len;i++){ int x=s[i]-‘a‘; if(!trie[root][x]) return 0; root=trie[root][x]; } return sum[root]; } int main(){ while(gets(s)){ if(!p){ if(strlen(s)) insert(); else p=1; } else printf("%d\n",find()); } }
标签:span 思路 nan define 前缀 pid 单词 auth limit
原文地址:http://www.cnblogs.com/cangT-Tlan/p/7401145.html