Babelfish(二分)
2015-09-24 21:11
267 查看
Babelfish
Description
You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.
Input
Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.
Output
Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".
Sample Input
Sample Output
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 37238 | Accepted: 15879 |
You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.
Input
Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.
Output
Output is the message translated to English, one word per line. Foreign 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
Sample Output
cat eh loops 题解:此处用到了sscanf的用法,很巧妙; 代码:
#include<stdio.h> #include<algorithm> #include<string.h> using namespace std; const int MAXN=100010; struct Node{ char en[20],ei[20];//无语开小了。。。 }; Node dt[MAXN]; int cmp(Node a,Node b){ return strcmp(a.ei,b.ei)<0; } int erfen(char *x,int l,int r){ while(l<=r){ int mid=(l+r)>>1; if(!strcmp(dt[mid].ei,x))return mid; if(strcmp(dt[mid].ei,x)>0)r=mid-1; else l=mid+1; } return -1; } int main(){ int dm=0; char str[50]; Node a; while(gets(str)){ if(str[0]=='\0')break; sscanf(str,"%s%s",a.en,a.ei);//这里很巧妙。。。 dt[dm++]=a; } sort(dt,dt+dm,cmp); while(~scanf("%s",str)){ int t=erfen(str,0,dm-1); if(t==-1)puts("eh"); else printf("%s\n",dt[t].en); } return 0; }
相关文章推荐
- java 操作excel
- 如何寻找连通域的重心
- cocos2d遍历所有body+判断触摸点是否在动态物体的形状内
- Factorial Trailing Zeroes
- WebAPI 身份认证解决方案——Phenix.NET企业应用软件快速开发平台.使用指南.21.WebAPI服务(一)
- java web总结(JNDI的配置)
- struts2结合spring json序列化问题
- caffe实现RNN(recursive Neural Network, recursive NN)
- poj 2187
- 一篇技术文章合格的标准 --- 一个对博客的理解
- LeetCode 16_3Sum Closest
- 动态规划—最长公共子序列问题
- Android方法数不能超过65K的解决方案
- lca转RMQ
- UVA 1349(二分图匹配)
- HDU 3394 Railway(点双连通分量与桥)
- 一篇技术文章合格的标准 --- 一个对博客的理解
- iOS多线程的一些使用心得
- PHP学习笔记(七):命名空间
- 图解HTTP协议 第5章 与HTTP协作的Web服务器学习笔记