Language of FatMouse(trie树)
来源:互联网 发布:idg 知乎 编辑:程序博客网 时间:2024/05/01 12:05
Description
We all know that FatMouse doesn't speak English. But now he has to be prepared since our nation will join WTO soon. Thanks to Turing we have computers to help him.
Input Specification
Input consists of up to 100,005 dictionary entries, followed by a blank line, followed by a message of up to 100,005 words. Each dictionary entry is a line containing an English word, followed by a space and a FatMouse word. No FatMouse word appears more than once in the dictionary. The message is a sequence of words in the language of FatMouse, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.
Output Specification
Output is the message translated to English, one word per line. FatMouse words not in the dictionary should be translated as "eh".
Sample Input
dog ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay
Output for Sample Input
catehloops
zoj这题真恶心,竟然卡内存,只能开到2倍,大一点都超内存。
AC代码:
#include<iostream>#include<algorithm>#include<cstdlib>#include<cstring>#include<string>#include<cstdio>#include<vector>#include<cmath>#include<map>using namespace std;#define T 100005#define inf 0x3f3f3f3f#define CRL(a) memset(a,0,sizeof(a))typedef long long ll;struct trie{string str;int kid[26];trie(){CRL(kid);}}tr[T<<1];char s[15],ss[15],str[25];int c=0;void insert(){int x=0,d,i;for(i=0;ss[i];++i){d = ss[i]-'a';if(tr[x].kid[d]==0){tr[x].kid[d]=++c;x=c;}elsex=tr[x].kid[d];}tr[x].str=s;}string find(){int i,d,x=0;for(i=0;s[i];++i){d = s[i]-'a';if(tr[x].kid[d]==0)return "";x=tr[x].kid[d];}return tr[x].str;}int main(){/*freopen("input.txt","r",stdin);*/ while(cin.getline(str,25),strcmp(str,"\0")){ int f=0; sscanf(str, "%s %s", s, ss);insert();}while(cin>>s){string t=find();if(t=="\0"){cout <<"eh\n";}else{cout << t<< endl;}}return 0;}
#include<iostream>#include<algorithm>#include<cstdlib>#include<cstring>#include<string>#include<cstdio>#include<vector>#include<cmath>#include<map>using namespace std;#define T 100005#define inf 0x3f3f3f3f#define CRL(a) memset(a,0,sizeof(a))typedef long long ll;struct trie{string str;int kid[26];trie(){CRL(kid);}}tr[T<<2];string s,ss,str;int c=0;void insert(){int x=0,d,i;for(i=0;ss[i];++i){d = ss[i]-'a';if(tr[x].kid[d]==0){tr[x].kid[d]=++c;x=c;}elsex=tr[x].kid[d];}tr[x].str=s;}string find(){int i,d,x=0;for(i=0;s[i];++i){d = s[i]-'a';if(tr[x].kid[d]==0)return "";x=tr[x].kid[d];}return tr[x].str;}int main(){/*freopen("input.txt","r",stdin);*/ while(getline(cin,str),str!="\0"){ int f=0;s="",ss="";for(int i=0;str[i];++i){if(str[i]==' '){f=1;}else if(f){ss+=str[i];}else{s+=str[i];}}insert();}while(cin>>s){string t=find();if(t=="\0"){cout <<"eh\n";}else{cout << t<< endl;}}return 0;}
- Language of FatMouse(trie树)
- ZOJ 1109 Language of FatMouse (trie树)
- zoj 1109 Language of FatMouse(字典树Trie)
- zoj 1109 Language of FatMouse (字典树Trie)
- zoj 1109 Language of FatMouse 【字典树】
- zoj 1109 Language of FatMouse(字典树)
- zoj1109-Language of FatMouse 字典树
- Language of FatMouse(map,空行处理)
- ZOJ1109 Language of FatMouse
- Language of FatMouse
- C - Language of FatMouse
- zoj_1109 Language of FatMouse
- ZOJ1109 Language of FatMouse
- ZOJ 1109 Language of FatMouse
- ZOJ1109 Language of FatMouse,BST
- zoj 1109 Language of FatMouse
- ZOJ 1109Language of FatMouse
- zoj 1109.Language of FatMouse
- PhantomJS基础及示例
- jquery 选择器写法
- 多线程
- QTP\UFT11.5破解
- POJ月赛题目Matrix Power Series
- Language of FatMouse(trie树)
- sql server FOR XML PATH 字符串拼接
- cocos2dx 利用CCOrbitCamera实现扑克牌翻牌效果
- aboutme
- Android--Dialog详细讲解
- blog-for-pluspower
- windows下使用GUI 把本地代码提交到git远程仓库
- 方向
- Unity3D保存数据到Json(加密、解密)