hdu1075
来源:互联网 发布:mac改用户名 编辑:程序博客网 时间:2024/05/22 17:50
链接:点击打开链接
题意:给出一句话按照密文所对应的原文输出应该输出的内容,具体看题目样例就可以
代码:
#include <iostream>#include <string.h>#include <stdio.h>using namespace std;char s[1000005][15];char s1[3005];int str[1000005][30],dis[1000005];int root;void in(char *s,int v){ int u=0; for(;*s;s++){ if(!str[u][*s-'a']) str[u][*s-'a']=root++; u=str[u][*s-'a']; } dis[u]=v;}int fi(char *s){ int u=0; for(;*s;s++){ if(!str[u][*s-'a']) return 0; u=str[u][*s-'a']; } return dis[u];} //字典树模板查找密文所对应的原文int main(){ char temp[3005]; int i,j,len; memset(str,0,sizeof(str)); memset(dis,0,sizeof(dis)); memset(s,0,sizeof(s)); scanf("%s",temp); i=root=1; while(1){ scanf("%s",s[i]); //用二维数组输入方便输出 if(strcmp(s[i],"END")==0) break; scanf("%s",s1); in(s1,i); i++; } scanf("%s",temp); getchar(); while(1){ j=0; memset(s1,0,sizeof(s1)); memset(temp,0,sizeof(temp)); gets(s1); if(strcmp(s1,"END")==0) break;// len=strlen(s1);// if(s1[len-1]>='a'&&s1[len-1]<='z')// continue; for(i=0;s1[i];i++){ //这个题最关键的就是假如最后一个单词没有标点不输出最后一个单词。。。 if(s1[i]>='a'&&s1[i]<='z') temp[j++]=s1[i]; else{ temp[j]='\0';// cout<<temp<<endl; if(temp[0]!='\0'){ //这个就是将一句话中的单词拆出来 if(fi(temp)!=0) printf("%s",s[fi(temp)]); else printf("%s",temp); temp[0]='\0'; //将头变成'\0'即可 j=0; } printf("%c",s1[i]); }// if(s1[i]=='\0')// break; } printf("\n"); } return 0;}
0 0
- hdu1075
- HDU1075
- hdu1075
- hdu1075
- hdu1075
- hdu1075
- hdu1075
- HDU1075
- hdu1075
- hdu1075
- hdu1075
- trie hdu1075
- hdu1075 map
- hdu1075【map】
- hdu1075 map
- hdu1075--还是字典树
- HDU1075 字典树
- hdu1075之字典树
- hdu 5373 the shortest problem
- 排序算法总结
- Ubuntu 15 VPN连接失败
- 浅谈MongoDB
- 移动应用界面设计的尺寸设置及规范
- hdu1075
- 第三周第二天
- JS验证身份证号码正确性
- Qt 串口类QSerialPort 使用笔记
- sunburnt 学习笔记 (一) sunburnt 简介和安装
- UITableView(基本设置和常用的协议方法)
- 使用DbUnit进行数据库操作的单元测试
- UI10_tableView的编辑
- BP神经网络对音频分类