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

对我来说不习惯写gets(line),一般都是getchar然后链接,此题不好处理啊。然后只有屈服了。注意的是getsline+assign的耗时很严重,能不用就不要用。

算法应该是裸的字典树,懒人就用stl_map也吼了。
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
string s,a,b;
char line[41];
map<string,string>Map;
int main()
{
while(true){
int pos;
gets(line);
s.assign(line);
if(s.empty())break;
pos=s.find(' ');
a=s.substr(0,pos);
b=s.substr(pos+1);
Map[b]=a;
}
while(cin>>s)
{
if(Map.find(s)==Map.end()) printf("eh\n");
else cout<<Map[s]<<endl;;
}
return 0;
}
然后舶来一份字典树:http://www.cnblogs.com/DreamUp/archive/2010/07/23/1783410.html
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100006
typedef struct node{
char s[12];
int h;
struct node *next[26];
}*Tree,T;
void init(Tree &root)
{
root=(Tree)malloc(sizeof(T));
root->h=0;
for(int i=0;i<26;i++)
root->next[i]=NULL;
} void insert(char path[],char s[],Tree root)
{
int len,i,j;
len=strlen(path);
for(i=0;i<len;i++)
{
if(root->next[path[i]-'a']==NULL)
{
Tree t=(Tree)malloc(sizeof(T));
for(j=0;j<26;j++)
{
t->next[j]=NULL;
t->h=0;
}
root->next[path[i]-'a']=t;
}
root=root->next[path[i]-'a'];
}
root->h=1;
strcpy(root->s,s);
} void find(char s[],Tree root)
{
int len,i;
len=strlen(s);
for(i=0;i<len;i++)
{
if(root->next[s[i]-'a']!=NULL)
root=root->next[s[i]-'a'];
else
break;
}
if(i==len && root->h==1)
puts(root->s);
else
puts("eh");
} int main()
{
Tree root;
int len,i;
char str[25],a[12],b[12];
init(root);
while(1)
{
gets(str);
len=strlen(str);
if(len==0)
break;
for(i=0;str[i]!=' ';i++);
strncpy(a,str,i);
a[i]=0;
strncpy(b,str+i+1,len-i-1);
b[len-i-1]=0;
insert(b,a,root);
}
while(scanf("%s",str)!=EOF)
find(str,root);
return 0;
}


												

zoj1109 水题(大神绕道) Language of FatMouse的更多相关文章

  1. C#回调函数的简单讲解与应用例子(最简单讲解,大神绕道)

    本博客一直以来的宗旨就是:用最简单的方式讲清楚不复杂的问题. 因为本人也很菜所以也没法讲太复杂HHHHHH...... 所以如果哪天某个大神看到了觉得讲的有问题欢迎指出. 话不多说进入正题.. ——— ...

  2. ACM学习历程—Hihocoder编程之美测试赛B题 大神与三位小伙伴(组合数学 )

    时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给你一个m x n (1 <= m, n <= 100)的矩阵A (0<=aij<=10000),要 ...

  3. 【初级为题,大神绕道】The app icon set named "AppIcon" did not have any applicable content 错误#解决方案#

    The app icon set named "AppIcon" did not have any applicable content 错误,怎样解决   按照您的错误提示您应该 ...

  4. 烟大 Contest1024 - 《挑战编程》第一章:入门 Problem A: The 3n + 1 problem(水题)

    Problem A: The 3n + 1 problem Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 14  Solved: 6[Submit][St ...

  5. 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题

    B - 大还是小? Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Description 输入两个实数,判断第一个数大 ...

  6. 烟大 Contest1025 - 《挑战编程》第二章:数据结构 Problem A: Jolly Jumpers(水题)

    Problem A: Jolly Jumpers Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 10  Solved: 4[Submit][Status] ...

  7. 【web前端面试题整理04】阿里一行之大神面对面

    前言 这段时间我在河南一家公司当了一段时间的前端主管,最后可耻的匿了,原因各种各样,最主要的就是不想呆在郑州了. 其实这里的同事还是很不错的,面对老总最后的挽留我不是没有动心,而是这个地方确实不太好, ...

  8. poj 1002:487-3279(水题,提高题 / hash)

    487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 236746   Accepted: 41288 Descr ...

  9. hdu 2041:超级楼梯(水题,递归)

    超级楼梯 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...

随机推荐

  1. JMeter打开脚本失败 如何解决?

    最近有碰到JMeter打开之前的脚本,报错了,见下图: 后来发现这是因为之前保存脚本的 jmeter 和这次打开脚本的 jmeter 版本不一致(图一)或者版本一致而插件没有保持同步(图二)的原因: ...

  2. 串口数据缓存java版

    接触串口很久了,一直以来将都是将串口读取出来的数组转换成字符串通过string.contains()查找是否包涵目标数组,自己感觉low到爆,所以写了一个byte-buffer,测试还是蛮好用的.希望 ...

  3. 【1414软工助教】团队作业9——测试与发布(Beta版本) 得分榜

    题目 团队作业9--测试与发布(Beta版本) 往期成绩 个人作业1:四则运算控制台 结对项目1:GUI 个人作业2:案例分析 结对项目2:单元测试 团队作业1:团队展示 团队作业2:需求分析& ...

  4. 201521123075 《Java程序设计》第12周学习总结

    1. 本周学习总结 2. 书面作业 将Student对象(属性:int id, String name,int age,double grade)写入文件student.data.从文件读出显示. 1 ...

  5. 数据库Mysql的安装及操作---数据引擎

    一.1.什么是数据           描述事物的符号记录称为数据.       2.什么是数据库         存放数据的仓库,只不过这个仓库在计算机上存储设备上. 二.Mysql的介绍     ...

  6. Maven第四篇【私有仓库、上传jar包、引用私服jar包、上传本地项目到私服】

    搭建私有服务器 前面已经说过了,我们使用Maven的使用,如果需要导入相对应的jar包,Maven首先会在我们的本地仓库中寻找->私有仓库->中心仓库- 然而,我们的本地仓库常常没有想要的 ...

  7. Log4j.properties属性文件

    log4j.properties文件属性介绍log4j.rootLogger = [ level ] , appenderName1, appenderName2, …#level : 设定日志记录的 ...

  8. python 集合的操作

    list_1 = set([1,2,3,4,5])#print(list_1,type(list_1))list_2 = set([1,2,3,6,7,8,9,10])#print(list_2,ty ...

  9. .NET Core 使用RabbitMQ

    RabbitMQ简介 AMQP,即Advanced Message Queuing Protocol,高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设计.消息中间件主要用于组件之间的 ...

  10. 去掉 Warning:$HADOOP_HOME is deprecated

    修改配置文件/etc/profile,增加环境变量HADOOP_HOME_WARN_SUPPRESS=1, 保存退出,再次启动hadoop,就不会出现警告信息了