HDU 1251 统计难题
来源:互联网 发布:金山数据恢复会员共享 编辑:程序博客网 时间:2024/06/14 06:57
注意用g++交,否则会超内存
#include<iostream>#include<cstdio>#include<cstring>#define maxn 26using namespace std;struct node{int cnt;node * next[maxn];node(){cnt=0;memset(next,0,sizeof(next));}};node *p,*root=new node();void insert(char *s){p=root;for(int i=0;s[i];i++){int id=s[i]-'a';if(p->next[id]==NULL) p->next[id]=new node(); //没有就新建节点 p=p->next[id];//当前节点 p->cnt++;//出现次数加一 }}int query(char *s){p=root;for(int i=0;s[i];i++){int id=s[i]-'a';if(p->next[id]==NULL) return 0;p=p->next[id]; }return p->cnt;}int main(){char s[20];while(gets(s),*s) insert(s);while(gets(s)) cout<<query(s)<<endl; }
0 0
- HDU 1251 统计难题
- HDU 1251 统计难题
- hdu 1251 统计难题
- HDU 1251:统计难题
- HDU 1251 统计难题
- Hdu-1251 统计难题
- hdu 1251 统计难题
- hdu 1251 统计难题
- hdu 1251 统计难题
- HDU-1251-统计难题
- HDU 1251 统计难题
- hdu 1251统计难题
- hdu 1251统计难题
- hdu 1251 统计难题
- HDU 1251 统计难题
- hdu 1251统计难题
- HDU 1251 统计难题
- hdu 1251 统计难题
- git 命令别名配置
- 使用AsyncTask异步更新UI界面
- 分桃记
- hdu 1588
- 修改eclipse界面
- HDU 1251 统计难题
- 代理回调分析和OC实现
- Android设置全屏
- HDU 5365
- HDU1000 A + B Problem
- Cocos2d-x过程动作CCProgressTo示例学习笔记
- Eclipse中的Web项目自动部署到Tomcat
- JavaSE基础--(二)IO部分
- PAT (Basic Level) Practise (中文)1001. 害死人不偿命的(3n+1)猜想