tjut 1251
来源:互联网 发布:电子书阅读器 知乎 编辑:程序博客网 时间:2024/06/03 05:52
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> using namespace std; struct node { int count; node *childs[26]; node() { count=0; int i; for(i=0;i<26;i++) childs[i]=NULL; } }; node *root=new node; node *current,*newnode; void insert(char *str) { int i,m; current=root; for(i=0;i<strlen(str);i++) { m=str[i]-'a'; if(current->childs[m]!=NULL) { current=current->childs[m]; ++(current->count); } else { newnode=new node; ++(newnode->count); current->childs[m]=newnode; current=newnode; } } } int search(char *str) { int i,m; current=root; for(i=0;i<strlen(str);i++) { m=str[i]-'a'; if(current->childs[m]==NULL) return 0; current=current->childs[m]; } return current->count; } int main() { char str[20]; while(gets(str),strcmp(str,"")) insert(str); while(gets(str)!=NULL) printf("%d\n",search(str)); return 0; }
0 0
- tjut 1251
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- tjut 5410
- JQuery加载Json对象到form
- Hibernate 对象的几种状态
- 可选项
- JQuery的each方法详解
- 关于异或(XOR)的有趣应用
- tjut 1251
- if语句
- 控件内容遇到导航条出现偏移的情况
- 第3课 Go控制,循环,选择,跳转语句
- Java线程的同步与死锁
- str()和repr()(及''操作符)以及python对json的简单操作
- ios第一天学习
- Nginx+Tomcat负载均衡配置
- POJ 2385 Apple Catching(DP)