随笔 - 531  文章 - 0  评论 - 3  阅读 - 10215 

查找单词个数

样例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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<br><br><br>1 2 3
2 3
1 2
3
2

 

 

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
#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);
 }

 

posted on   towboat  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示