ZOJ1109 Language of FatMouse
2016-04-01 15:44
246 查看
题目链接:ZOJ1109
Language of FatMouse
Time Limit: 10 Seconds Memory Limit: 32768 KB
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".
题意:左面是人的语言,右面是老鼠的,我们要把每一个给出来的老鼠语转换成人的语言。
题目分析:跟之前HDU1075火星文的题几本一样,我们只需要标记好串尾就行了。
Language of FatMouse
Time Limit: 10 Seconds Memory Limit: 32768 KB
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 ogday cat atcay pig igpay froot ootfray loops oopslay atcay ittenkay oopslay
Output for Sample Input
cat eh loops
题意:左面是人的语言,右面是老鼠的,我们要把每一个给出来的老鼠语转换成人的语言。
题目分析:跟之前HDU1075火星文的题几本一样,我们只需要标记好串尾就行了。
// // main.cpp // ZOJ1109 // // Created by teddywang on 16/4/1. // Copyright © 2016年 teddywang. All rights reserved. // #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef struct node { int num; node *next[26]; }trienode; trienode *root; char s[100040][13]; int l; void insert_node(char *t,int num) { int len=strlen(t); trienode *h,*r=root; for(int i=0;i<len;i++) { int buf=t[i]-'a'; if(r->next[buf]==NULL) { h=new node; h->num=-1; for(int j=0;j<26;j++) h->next[j]=NULL; r->next[buf]=h; r=h; } else r=r->next[buf]; } r->num=num; } int find(char *t) { int len=strlen(t); trienode *r=root; for(int i=0;i<len;i++) { int buf=t[i]-'a'; if(r->next[buf]==NULL) return -1; else r=r->next[buf]; } return r->num; } void del(trienode *r) { for(int i=0;i<26;i++) { if(r->next[i]!=NULL) del(r->next[i]); } free(r); } int main() { root=new node; root->num=-1; for(int i=0;i<26;i++) root->next[i]=NULL; l=0; char t[30]; while(gets(t)&&t[0]!='\0') { int i=0; for(i=0;t[i]!=' ';i++) { s[l][i]=t[i]; } insert_node(t+i+1,l); l++; memset(t,0,sizeof(t)); } while(~scanf("%s",t)) { int pos=find(t); if(pos==-1) printf("eh\n"); else printf("%s\n",s[pos]); } del(root); }
相关文章推荐
- tinycore Network card configuration during exec bootlocal.sh
- sqlserver 分区表
- 深入分析Java的序列化与反序列化
- JavaScript —— JS截取字符串substr 和 substring方法的区别
- zabbix3.0 LNMP安装部署 centos7
- 【HDU】 1022 Train Problem I
- 数据库连接池原理分析
- 自定义View学习之12/7(进度条之混合模式)
- [poj 2528] Mayor's posters 线段树+离散化
- hadoop_2_完全分布式高可用
- 特征选择
- Android MeterDesign(一)
- 如何判断input 中checkbox 中是否勾选
- Android 二维码生成
- [Mark] 百度地图 Https
- mongodb的安装,开启,连接
- Ubuntu12.04 编译 Hadoop 2.6.4 源码
- 【poj 2528】Mayor's posters 题意&题解&代码(C++)
- hadoop_1_完全分布式
- 你真的会写单例模式吗——Java实现