若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1640: Language of FatMouse

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,297

题目描述

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 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 is the message translated to English, one word per line. FatMouse words not in the dictionary should be translated as "eh".

样例输入

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay

样例输出

cat
eh
loops

参考代码

#include<stdio.h>
#include<string.h>
struct 
{
    char z[15],j[15];
}
c[100010];
int fac(int n, char *a) 
{
    int left=0,right=n,mid;
    while(left<right) 
    {
        mid=(left+right)/2;
        if(strcmp(c[mid].j,a) == 0)
                    return mid; else if(strcmp(c[mid].j,a) >  0)
                    right=mid; else
                    left = mid + 1;
    }
    return -1;
}
int main() 
{
    int n=0,k=1;
    char a[30];
    while(gets(a)&&strlen(a)!=0) 
    {
        sscanf(a,"%s%s",c[n].z,c[n].j);
        n++;
    }
    while(gets(a)) 
    {
        k=fac(n,a);
        if(k==-1)
                    puts("eh"); else
                    puts(c[k].z);
    }
    return 0;
}

解析

暂无

hustoj

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

Skip Dreams孤独患者 原站点
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist