banana band bee absolute acm    ba b band abc

#include<iostream>
using namespace std;
//数据结构
struct Treenode{
int count;
Treenode *next[];
Treenode(){
count=;
for(int i=;i<;i++)
next[i]=NULL;
}
};
//插入建树
void insert(Treenode *&root,char *word){
if(root==NULL)
root=new Treenode();
Treenode *location=root;
int i=,branch=;
while(word[i])
{
branch=word[i]-'a';
if(location->next[branch])
location->next[branch]->count++;
else
location->next[branch]=new Treenode();
i++;
location=location->next[branch];
}
}
//查找
int search(Treenode *root,char *word)
{
if(root==NULL) return ;
Treenode *location=root;
int branch=,i=,ans;
while(word[i])
{
branch=word[i]-'a';
if(!location->next[branch])
return ;
i++;
location=location->next[branch];
ans=location->count;
}
return ans;
} int main()
{
char word[];
char ask[];
Treenode *root=NULL; while(gets(word))
{
if(word[]=='\0') break;
insert(root,word);
}
while(gets(ask))
{
cout<<search(root,ask)<<endl;
}
getchar();
return ;
}

最新文章

  1. 通过配置http拦截器,来进行ajax请求验证用户登录的页面跳转
  2. Atitit。木马病毒原理机密与概论以及防御
  3. Linux初学 - 解决chkconfig Segmentation fault(core dumped)
  4. WordPress模板常用函数
  5. python自学笔记一
  6. 移植FastBlur模糊算法至SDL
  7. linux c遍历文件夹 和文件查找的方法
  8. 转:三十一、Java图形化界面设计——布局管理器之GridLayout(网格布局)
  9. Linux系统编程(14)——shell常用命令
  10. ios像素点颜色取样
  11. freemarker 遍历 hashmap 到select option
  12. Spring Cloud 入门教程 - Eureka服务注册与发现
  13. 在WINDOWS中安装使用GSL(MinGW64+Sublime Text3 &amp; Visual Studio)
  14. JQuery——选择器
  15. Python 3+selenium+unittest+HTMLTestRunner生成测试报告
  16. CentOS7+CDH5.14.0安装全流程记录,图文详解全程实测-8CDH5安装和集群配置
  17. Java中有关Null的9件事(转)
  18. Linux查看操作系统版本命令
  19. sql server 语法 MSDN
  20. centos7 静默安装oracle

热门文章

  1. 从0开始学Swift笔记整理(五)
  2. 动手写一个Remoting接口测试工具(附源码下载)
  3. ubuntu 12.04 安装 redis
  4. windows下使用体验更好的控制台——ConsoleZ
  5. [MFC] 从文件读取与向文件添加数据
  6. [MFC] MFC 用mciSendString加载WAV资源文件
  7. Spring依赖注入(IOC)那些事
  8. ThreadLocal线程范围内的共享变量
  9. JS 数字转换为大写金额
  10. mysql 5.7 win7 压缩版安装