hdu 1075 What Are You Talking About
2015-08-23 14:05
274 查看
乱写的代码,之所以乱写,是为了复习字典树和map
要注意文章单词间可能有多个空格和字符
要注意文章单词间可能有多个空格和字符
#include<iostream> #include<cstdio> #include<map> #include<cstring> #include<string> using namespace std; map<string,string>mapp; string str; struct stu { int flag; stu* a[26]; stu() { flag=0; for(int i=0;i<26;i++) a[i]=NULL; } }; stu* root=new stu(); void build(stu *root,int cnt) { int x=str[cnt]-'a'; if(root->a[x]==NULL) root->a[x]=new stu(); root=root->a[x]; if(cnt==str.size()-1) { root->flag=1; return; } build(root,cnt+1); } string find(stu* root,int cnt) { int x=str[cnt]-'a'; if(x<0||x>25) return str; if(root->a[x]==NULL) return str; root=root->a[x]; if(cnt==str.size()-1) { if(root->flag==1) return mapp[str]; else return str; } else return find(root,cnt+1); } int main() { //cin.sync_with_stdio(false); string cmd; cin>>cmd; while(cin>>cmd&&cmd!="END") { cin>>str; mapp[str]=cmd; build(root,0); } cin>>cmd; getchar(); while(getline(cin,cmd)&&cmd!="END") { for(int i=0;i<cmd.size();i++) { str=""; while(cmd[i]>='a'&&cmd[i]<='z') str+=cmd[i++]; cout<<find(root,0)<<cmd[i]; } cout<<endl; } return 0; }
相关文章推荐
- JNDI:对java:comp/env的研究
- 文本计算器
- 二叉树的前序、中序和后序遍历
- 实木地板安装需要注重细节
- 开源框架数据源配置
- Monthly Expense(二分查找)
- [HDU 2586] How far away ? 最近公共祖先
- Monthly Expense(二分查找)
- Spring AOP + AspectJ annotation example
- JavaSE----API之集合(Collection、List及其子类、Set及其子类、JDK1.5新特性)
- Windows Server 2016第三个技术预览版新技术
- Windows Server 2016第三个技术预览版新技术
- House Robber
- hdu 2845 Beans
- 编写高质量代码改善C#程序的157个建议——建议128:考虑让派生类的名字以基类名字作为后缀
- 二维平面推断点在三角
- 程序员谈网络改变我们的生活
- Android context使用场景介绍(1)
- (大数据工程师学习路径)第五步 MySQL参考手册中文版----MySQL函数和操作符
- Linux基础命令学习