Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 29059 Accepted: 12565

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 ogday
cat atcay
pig igpay
froot ootfray
loops oopslay atcay
ittenkay
oopslay

Sample Output

cat
eh
loops 题意:给一个字典,输入若干个字符串,问再字典中与它对应的字符串,若没有输出“eh”;

 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
char s1[][],s2[][]; struct node
{
int flag;
struct node *next[];
};
struct node* creat()
{
struct node *p = (struct node *)malloc(sizeof(struct node));
p->flag = ;
for(int i = ; i < ; i++)
p->next[i] = NULL;
return p;
} void insert(struct node *p, char s[],int cnt)
{
for(int i = ; s[i]; i++)
{
if(p->next[s[i]-'a'] == NULL)
p->next[s[i]-'a'] = creat();
p = p->next[s[i]-'a'];
}
p->flag = cnt;
}
int search(struct node *p, char s[])
{
for(int i = ; s[i]; i++)
{
if(p->next[s[i]-'a'] == NULL)
return -;
p = p->next[s[i]-'a'];
}
return p->flag;
}
int main()
{
char s[],str[];
int cnt = ;
struct node *root;
root = creat();
while(gets(s))
{
if(strcmp(s,"") == )
break;
sscanf(s,"%s %s",s1[cnt],s2[cnt]);
insert(root,s2[cnt],cnt);
cnt++;
}
while(scanf("%s",str)!= EOF)
{
int f = search(root,str);
if(f == -)
printf("eh\n");
else printf("%s\n",s1[f]);
}
return ;
}
												

poj 2503 Babelfish(字典树哈希)的更多相关文章

  1. poj 2503 Babelfish(字典树或map或哈希或排序二分)

    输入若干组对应关系,然后输入应该单词,输出对应的单词,如果没有对应的输出eh 此题的做法非常多,很多人用了字典树,还有有用hash的,也有用了排序加二分的(感觉这种方法时间效率最差了),这里我参考了M ...

  2. poj 2503 Babelfish(字典树或着STL)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 35828   Accepted: 15320 Descr ...

  3. Colored Sticks (字典树哈希+并查集+欧拉路)

    Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27704   Accepted: 7336 Description You ...

  4. poj 2503 Babelfish(Map、Hash、字典树)

    题目链接:http://poj.org/bbs?problem_id=2503 思路分析: 题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找. 代码( ...

  5. poj 2503:Babelfish(字典树,经典题,字典翻译)

    Babelfish Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 30816   Accepted: 13283 Descr ...

  6. POJ 2503 Babelfish(map,字典树,快排+二分,hash)

    题意:先构造一个词典,然后输入外文单词,输出相应的英语单词. 这道题有4种方法可以做: 1.map 2.字典树 3.快排+二分 4.hash表 参考博客:[解题报告]POJ_2503 字典树,MAP ...

  7. poj 3007 Organize Your Train part II(静态字典树哈希)

    Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6700 Accepted: 1922 Description RJ Freigh ...

  8. POJ 2503 Babelfish

    Babelfish Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 28766 Accepted: 12407 Descripti ...

  9. Watto and Mechanism CodeForces - 514C (字典树,哈希)

    大意: 给定字符串集$S$, 每次询问给出字符串$a$, 求$S$中是否存在一个字符串恰好与$a$相差一个字符. 直接建字典树暴力复杂度是$O(n\sqrt{n})$, 也可以用set维护所有哈希值, ...

  10. poj 2513(欧拉路径+字典树映射)

    题目链接:http://poj.org/problem?id=2513 思路:题目还是很简单的,就是判断是否存在欧拉路径,我们给每个单词的头和尾映射序号,统计度数.对于给定的无向图,当且仅当图连通并且 ...

随机推荐

  1. 【网络通信】服务器端Socket监听80端口,建立连接传输数据时也是使用的80端口么?

    1. 服务器端Socket监听80端口,建立连接传输数据时也是使用的80端口么? 答:对.建立连接时服务器会分配一个新的Socket,但是用的源端口号还是80端口.套接字是由协议类型.源IP.目的IP ...

  2. Java(Android)线程池 总结

        JAVA的Executors源码:(可以看出底层都是通过ThreadPoolExecutor来具体设置的~) public static ExecutorService newCachedTh ...

  3. 如何学习一门新技术-iOS开发

    如何快速学习一门新技术 以CoreBluetooth 蓝牙开发为例.我们可以从官方获得的资源有:SampleCode, Documentation,API Reference. 先从Documenta ...

  4. linux中history命令使用与配置

    history中设置显示命令的执行时间 vi /root/.bashrc HISTTIMEFORMAT="%Y-%M-%D %H:%M:%S" export HISTTIMEFOR ...

  5. 关于EF查询表里的部分字段

    这个在项目中用到了,在网上找了一下才找到,留下来以后自已使用. List<UniversalInfo> list =new List<UniversalInfo>(); lis ...

  6. kissy

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  7. HTML5 文件域+FileReader 读取文件(二)

    一.读取文本文件内容,指定字符编码 <div class="container"> <!--文本文件验证--> <input type="f ...

  8. Tomcat-java.lang.IllegalArgumentException: Document base F:apps does not exist or is not a readable

    启动Tomcat的时候,报错:java.lang.IllegalArgumentException: Document base F:apps does not exist or is not a r ...

  9. 游标中的static参数

    以下测试用例将演示,使用static的游标和不使用的区别: if object_id(N't_test',N'u') is not null drop table t_test go create t ...

  10. javascript 之DOM篇

    要怎么样的开场白才能使我有力气再更新学习进度呢?啊啊啊啊啊,表示好累啊~~~默念“棒棒棒,我最棒~”召唤精气神开总结敲字咯.哈哈哈. --------------------------------- ...