查找单词个数
样例:
3 9 you are a good boy ha ha o yeah 13 o my god you like bleach naruto one piece and so do i 11 but i do not think you will get all the points 5 you i o all naruto
1 2 3 2 3 1 2 3 2
#include <iostream> #include <cstring> using namespace std; const int N=5e5+100; int tot=1,ch[N][27]; int n,m,b[N][110]; char s[N]; void insert(int id,char *s){ int u =1; int l=strlen(s+1); for(int i=1;i<=l;i++){ int c= s[i]-'a'; if(ch[u][c]==0) ch[u][c]=++tot; u=ch[u][c]; } b[u][id]=1; } void find(char *s){ int u=1; int flag=1; int len=strlen(s+1); for(int i=1;i<=len;i++){ int c= s[i]-'a'; if(ch[u][c]==0){ flag=0; break; } u=ch[u][c]; } if(flag){ for(int i=1;i<=n;i++) if(b[u][i]) cout<<i<<' '; } cout<<endl; } signed main(){ int i,x; cin>>n; for(int j=1;j<=n;j++){ cin>>x; for(i=1;i<=x;i++) cin>>s+1,insert(j,s); } cin>>m; for(i=1;i<=m;i++) cin>>s+1, find(s); }
标签:char,int,理解,P3879,TJOI2010,naruto,include From: https://www.cnblogs.com/towboa/p/17195904.html