hdu 1251 统计难题
来源:互联网 发布:中国电信测速软件下载 编辑:程序博客网 时间:2024/05/17 09:05
字典树,题目并无难度,关键是如何输入空格推出循环
用getline输入C++的字符串要加上 #include<string>..........
这题G++交会无限超内存
#include<iostream>#include<cstdio>#include<string>using namespace std;string str;struct stu{int m;stu *a[26];stu(){m=0;for(int i=0;i<26;i++) a[i]=NULL;}};stu *p=new stu();void insert(stu *root,int cnt){if(cnt==str.size()) return;int x=str[cnt]-'a';if(root->a[x]==NULL){root->a[x]=new stu();}root=root->a[x];root->m++;insert(root,cnt+1);}void solve(stu *root,int cnt){int x=str[cnt]-'a';root=root->a[x];if(root==NULL){cout<<"0"<<endl;return;}if(cnt==str.size()-1){cout<<root->m<<endl;}else solve(root,cnt+1);}int main(){cin.sync_with_stdio(false);while(getline(cin,str)&&str!="") insert(p,0);while(cin>>str) solve(p,0);return 0;}
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 统计难题
- 数据仓库
- 12219 - Common Subexpression Elimination(表达式树)
- Spring(Struts、Hibernate优势 + Spring IOC、AOP + Spring实际开发过程)
- uva_658_It's not a Bug, it's a Feature!(最短路)
- 翻转bitorder
- hdu 1251 统计难题
- c++ 类的赋值运算符=的重载,以及深拷贝和浅拷贝
- 菲利亚指的是在对善的追寻中同行,共同住在一个社区的人们之间的友情;
- poj 1182
- hdu 3371 Connect the Cities 最小生成树
- exit与_exit
- 关于《一种基于球面透视投影约束的鱼眼镜头校正方法》的流程
- HDU 1212 Big Number(简单的大数取模)
- 记票统计(java版整理)