huu 1251

复制代码
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <algorithm>
 6 #include <utility>
 7 #include <vector>
 8 #include <map>
 9 #include <queue>
10 #include <stack>
11 #include <cstdlib>
12 #include <deque>
13 #include <set>
14 typedef long long ll;
15 #define lowbit(x) (x&(-x))
16 #define ls l,m,rt<<1
17 #define rs m+1,r,rt<<1|1
18 using namespace std;
19 const  int N=1e6+3;
20 int tree[N][30];//26个字母
21 int num[N];
22 char s[15];
23 int pos;
24 void insert(char s[]){
25     int root=0,i;
26     for(i=0;s[i];i++){
27         int x=s[i]-'a';
28         if(!tree[root][x]){
29             tree[root][x]=pos++;
30         }
31         root=tree[root][x];
32         num[root]++;
33     }
34 }
35 int  query(char s[]){
36     int i;
37     int root=0;
38     for(i=0;s[i];i++){
39         int x=s[i]-'a';
40         if(!tree[root][x]){
41             return  0;
42         }
43         root=tree[root][x];
44     }
45     return num[root];
46 }
47 int main()
48 {   
49    pos=1;
50    /*
51     memset(tree,0,sizeof(tree));
52     memset(num,0,sizeof(num));
53     */
54     //加上上面的会超内存
55     while(gets(s)){//不要用scanf
56         if(s[0]==NULL)
57             break;
58             insert(s);     
59     }
60     while(gets(s)){
61         printf("%d\n",query(s));
62     }
63     return  0;
64 }
复制代码

 

posted on   cltt  阅读(322)  评论(0编辑  收藏  举报

编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示