hdu-1075 What Are You Talking About
来源:互联网 发布:淘宝白酒 编辑:程序博客网 时间:2024/05/16 11:00
//根据思路写,这题count值变成字符串,在建树的时候在字符串最后的结点保存一个对应的字符串,//这样在查找的时候,可以根据这样一直查找到最后一个结点,如果不为空,就输出对应的字符串,否则输出原字符串。#include<cstdio>#include<string>#include<cstring>#include<malloc.h>#include<iostream>using namespace std;#define N 26typedef struct node{ char str[15]; struct node *next[N];}*tree;void zeronode(tree head)//初始化{ int i; for(i=0;i<N;i++) head->next[i]=NULL; strcpy(head->str,"");}void insert(tree head,string s,string ss)//s是字典,ss是火星文{ tree p=head; int len=ss.length(),i; for(i=0;i<len;i++)//建树时只需要考虑树为空时的情况, { int index=ss[i]-'a'; if(p->next[index]==NULL) { tree tem=(tree)calloc(1,sizeof(node)); zeronode(tem); p->next[index]=tem; } p=p->next[index];//p一直到字符串的最后一个结点 } strcpy(p->str,s.c_str());//函数返回一个指向纯c的指针,就是把string,变为c语言的字符串}string find(tree head,string s){ int len=s.length(),i; for(i=0;i<len;i++) { if(!islower(s[i]))//如果有非英文字母,返回原字符串 return s; int index=s[i]-'a'; if(head->next[index]==NULL)//如果找不到,也返回 return s; head=head->next[index]; } if(strcmp(head->str,"")!=0)//如果结点最后非空,返回对应的字符串 return head->str; else return s;//否则返回原字符串}void delet(tree head){ int i; for(i=0;i<N;i++) if(head->next[i]!=NULL) delet(head->next[i]); free(head);}char s[11],ss[3001];int main(){ tree head=(tree)calloc(1,sizeof(node)); zeronode(head); scanf("%s",s); while(scanf("%s",s)!=EOF) { if(strcmp(s,"END")==0) break; scanf("%s",ss); insert(head,s,ss); } scanf("%s",s); getchar(); int i; while(gets(ss)) { if(strcmp(ss,"END")==0)break; string s_word,s_wars; s_word.clear(); s_wars.clear(); int len=strlen(ss);; for(i=0;i<len;i++) { if(islower(ss[i])) s_wars+=ss[i]; else { s_wars=find(head,s_wars); s_word+=s_wars; s_word+=ss[i]; s_wars.clear(); } } cout<<s_word<<endl; } delet(head); return 0;}
#include<iostream>#include<string>#include<map>using namespace std;int main(){ string s,s1; map<string,string>m; cin>>s; while(cin>>s&&s!="END") { cin>>s1; m[s1]=s; } cin>>s; getchar(); char tmp[3005]; while(1) { gets(tmp); if(strcmp(tmp,"END")==0) break; s1=""; int i,len; len=strlen(tmp); for(i=0;i<len;i++) { if(!(tmp[i]>='a'&&tmp[i]<='z')) { if(m[s1]!="") cout<<m[s1]; else cout<<s1; s1=""; cout<<tmp[i]; } else s1+=tmp[i]; } cout<<endl; } return 0;}
0 0
- hdu 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- HDU-1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- HDU-1075-What Are You Talking About
- HDU 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- Hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- hdu-1075-What Are You Talking About
- hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About
- Java保留有效位数的4种方法
- 个人重构机房收费系统——SqlHelper介绍
- C的“类型提升”
- 需求用例分析之四:业务规则
- Matlab曲线拟合工具箱CFTOOL实例解析
- hdu-1075 What Are You Talking About
- 最长单调递增子序列
- Android网络传输中必用的两个加密算法:MD5 和 RSA (附java完成测试代码)
- MATLAB的曲线拟合
- 最长单调递增子序列
- 新的开始!终于来到CSDN了,看看能坚持多久
- matlab find函数用法
- C++箭头(->)运算符的重载
- linux中fork()函数详解(原创!!实例讲解)