博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2503.Babelfish-sscanf()函数+strcmp()函数+二分
阅读量:4985 次
发布时间:2019-06-12

本文共 1994 字,大约阅读时间需要 6 分钟。

 
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 44545   Accepted: 18803

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

dog ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay

Sample Output

catehloops

Hint

Huge input and output,scanf and printf are recommended.
 
 

题意就是输入一堆字符串,左边的对应着右边的,然后下面给出右边的,让你输出来左边的。

输入字符串的时候,碰到空行就不再输入了。就用strlen就可以。

处理字符串的时候,在这里卡住了,后来解决了,靠strcmp,sscanf。

二分二分!!!

 
代码:
#include
using namespace std;const int N=1e5+10;struct node{ char s1[25],s2[25];}a[N];int n;int cmp(node a,node b){ return strcmp(a.s2,b.s2)<0; //感觉好厉害(;´д`)ゞ}int main(){ n=0; char str[50]; while(gets(str)){ if(str[0]=='\0') break; sscanf(str,"%s%s",a[n].s1,a[n].s2); //好厉害(;´д`)ゞ n++; } sort(a,a+n,cmp); while(gets(str)){ int l=0,r=n,mid,flag=1; while(l<=r){ //二分 mid=(l+r)>>1; if(strcmp(str,a[mid].s2)==0){ printf("%s\n",a[mid].s1); flag=0;break; } else if(strcmp(str,a[mid].s2)<0) r=mid-1; else l=mid+1; } if(flag) printf("eh\n"); } return 0;}

 

 

 

 

 

 

转载于:https://www.cnblogs.com/ZERO-/p/7128855.html

你可能感兴趣的文章
ME525+ Defy+ 刷机指南[zz]
查看>>
支持触屏的jQuery轮播图插件
查看>>
Codesmith
查看>>
差一点搞混了Transactional注解
查看>>
javascript基本函数
查看>>
C#转义字符
查看>>
前端公共库cdn服务推荐//提高加载速度/节省流量
查看>>
python openpyxl内存不主动释放 ——关闭Excel工作簿后内存依旧(MemoryError)
查看>>
snprintf 返回值陷阱 重新封装
查看>>
asp.net GridView多行表头的实现,合并表头
查看>>
C#套打
查看>>
PolyCluster: Minimum Fragment Disagreement Clustering for Polyploid Phasing 多聚类:用于多倍体的最小碎片不一致聚类...
查看>>
【每日进步】July 2012
查看>>
327 作业
查看>>
sql 取汉字首字母
查看>>
javascript 封装ajax(多版本)
查看>>
bzoj4034: [HAOI2015]树上操作(树剖)
查看>>
android-Activity
查看>>
${sessionScope.user}的使用方法
查看>>
IOS断点下载
查看>>