HDU1251 统计难题
来源:互联网 发布:im聊天软件蓝色 编辑:程序博客网 时间:2024/06/05 10:03
第一次见到 以输入空行结束 学到了
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;int trie[400001][26],len,root,tot,sum[400001]; char s[11];//这里的s设为全局变量,插入和查询都是用的这个s void insert(){ len=strlen(s); root=0; for(int i=0;i<len;i++) { int id=s[i]-'a'; if(!trie[root][id]) trie[root][id]=++tot; //如果root子节点不含id所表示的字母,那么给trie[root][id]编号 sum[trie[root][id]]++;//sum表示以trie[root][id]为前缀的单词出现的的次数 root=trie[root][id];//更改根节点,继续向下 }}int search(){ root=0; len=strlen(s);//此时的s为要查询的前缀 for(int i=0;i<len;i++) { int id=s[i]-'a'; if(!trie[root][id]) return 0; root=trie[root][id]; } return sum[root];}int main(){ while(gets(s)&&strcmp(s,"")!=0){ insert();}while(cin>>s){printf("%d\n",search());}}
阅读全文
0 0
- 统计难题 hdu1251
- HDU1251统计难题
- 统计难题 hdu1251
- HDU1251-统计难题
- 【统计难题】 hdu1251
- hdu1251统计难题
- hdu1251(统计难题)
- HDU1251:统计难题
- hdu1251统计难题
- HDU1251 统计难题
- hdu1251 统计难题 (Trie)
- hdu1251 统计难题 trie
- HDU1251-统计难题
- hdu1251 统计难题
- hdu1251-统计难题
- Hdu1251 统计难题
- hdu1251统计难题
- C++统计难题hdu1251
- [笔记]MyEclipse For Mac 快捷键
- sdnu1314.切粉丝
- 连接数组、字符串方法总结
- 通过外网ip访问服务器之tomcat配置
- 阿里云海外服务器安装centos出现问题requires: libmysqlclient.so.18()(64bit)
- HDU1251 统计难题
- git与tag命令小结
- yolo.cfg文件
- 杭电oj 1075 map的使用
- Java拓展——随机数小程序
- 算法复杂度分析
- Unity 通过服务器加载配置文件(Text/XML/Json)
- 博客第一篇
- 通过一个例子来探讨交互式环境下输入