zoj1109 水题(大神绕道) Language of FatMouse
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的更多相关文章
- C#回调函数的简单讲解与应用例子(最简单讲解,大神绕道)
本博客一直以来的宗旨就是:用最简单的方式讲清楚不复杂的问题. 因为本人也很菜所以也没法讲太复杂HHHHHH...... 所以如果哪天某个大神看到了觉得讲的有问题欢迎指出. 话不多说进入正题.. ——— ...
- ACM学习历程—Hihocoder编程之美测试赛B题 大神与三位小伙伴(组合数学 )
时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 给你一个m x n (1 <= m, n <= 100)的矩阵A (0<=aij<=10000),要 ...
- 【初级为题,大神绕道】The app icon set named "AppIcon" did not have any applicable content 错误#解决方案#
The app icon set named "AppIcon" did not have any applicable content 错误,怎样解决 按照您的错误提示您应该 ...
- 烟大 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 ...
- 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题
B - 大还是小? Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Description 输入两个实数,判断第一个数大 ...
- 烟大 Contest1025 - 《挑战编程》第二章:数据结构 Problem A: Jolly Jumpers(水题)
Problem A: Jolly Jumpers Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 10 Solved: 4[Submit][Status] ...
- 【web前端面试题整理04】阿里一行之大神面对面
前言 这段时间我在河南一家公司当了一段时间的前端主管,最后可耻的匿了,原因各种各样,最主要的就是不想呆在郑州了. 其实这里的同事还是很不错的,面对老总最后的挽留我不是没有动心,而是这个地方确实不太好, ...
- poj 1002:487-3279(水题,提高题 / hash)
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 236746 Accepted: 41288 Descr ...
- hdu 2041:超级楼梯(水题,递归)
超级楼梯 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Su ...
随机推荐
- CSS背景效果
前面的话 本文将详细介绍CSS背景效果 条纹背景 [双条纹背景] background:linear-gradient(#fb3 50%, #58a 50%); background-size: 10 ...
- grunt之concat、cssmin、uglify
周末有点懒,跑去看了<智取威虎山>,手撕鬼子的神剧情节被徐老怪一条回忆线就解释过去了,牛到极致尽是这种四两拨千斤的处理方式,手撕加分,四星推荐. --------------------- ...
- linux一周学习总结
对于linux,之前也完全没有接触过,完全零基础小白.来到马哥以后,进入学习也有一周时间 ,一周里老师带我们学习了很多指令,下面,我就自己的理解和老师讲授的内容对linux中的一些指令做一个简单的小总 ...
- ★浅谈Spanking情节
- Spring Ioc DI 原理
IOC(DI):其实这个Spring架构核心的概念没有这么复杂,更不像有些书上描述的那样晦涩.Java程序员都知道:java程序中的每个业务逻辑至少需要两个或以上的对象来协作完成,通常,每个对象在使用 ...
- CSS基础知识摘要
元素分类 块级元素 什么是块级元素?在html中<div>. <p>.<h1>.<form>.<table>.<ul> 和 &l ...
- css3新特性---(border,Background部分)
boder属性新特性: border-radius 设置或检索对象使用圆角边框 border-top-left-radius 设置或检索对象左上角圆角边框 border-top-right-rad ...
- 团队作业10——复审和事后分析(Beta版本)
团队作业10--事后分析(Beta版本) http://www.cnblogs.com/newteam6/p/6953992.html 团队作业10--复审(Beta版本) http://www.cn ...
- Java学习7——一些注意的地方
(学习运算符.if和switch分支.for与while与do...while循环.break和continue.递归,内容和C++没差,挑了几个注意点) 运算符 逻辑与(&)和短路与(&am ...
- 201521123016 《Java程序设计》第3周学习总结
1. 本周学习总结 2. 书面作业 2.1代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; ...