hash Babelfish poj 2503
来源:互联网 发布:c语言swich case 编辑:程序博客网 时间:2024/05/17 03:44
Babelfish
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 27380 Accepted: 11823
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
2503Accepted5068K235MSC++1376B
#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define SIZE 199999struct Node { char key[12], fore[12]; bool flag; Node () { flag = false; }} table[SIZE];unsigned int BKDRHash(char *str){ unsigned int seed = 131; unsigned int hash = 0; while (*str) { hash = hash * seed + (*str++); } return (hash & 0x7FFFFFFF)%SIZE;}void insert(char *s1, char *s2){ int pos = BKDRHash(s2), m = 0; while (table[pos].flag){ pos += 2 * (++m) - 1; if (pos >= SIZE) pos -=SIZE; } strcpy(table[pos].key, s2); strcpy(table[pos].fore, s1); table[pos].flag = true;}int main(){ char buff[50], s1[20], s2[20]; while (gets(buff) && buff[0] != '\0') { sscanf (buff, "%s %s", s1, s2); insert (s1, s2); } while (scanf ("%s", s1) != EOF){ int pos = BKDRHash(s1), m = 0; bool flag = false; while (table[pos].flag){ if (strcmp(table[pos].key, s1) == 0) { printf ("%s\n", table[pos].fore); flag = true; break; } else { pos += 2 * (++m) - 1; pos = (pos >=SIZE ? pos -SIZE : pos); } } if (!flag) printf ("eh\n"); getchar(); } return 0;}
- POJ 2503 Babelfish(HASH)
- poj 2503 Babelfish 【hash】
- POJ 2503 Babelfish (Hash)
- hash Babelfish poj 2503
- POJ 2503 Babelfish(Hash)
- POJ 2503 BABELFISH (HASH)
- POJ 2503 Babelfish hash / qsort+ bsearch
- Poj 2503 Babelfish (Trie / STL / BKDR Hash)
- POJ 2503 Babelfish(hash + map)
- poj 2503 Babelfish(hash or 字典树)
- POJ 2503 Babelfish(map或hash或排序二分)
- poj 2503 Babelfish
- poj 2503 Babelfish
- POJ 2503 Babelfish
- POJ 2503 Babelfish
- poj 2503 Babelfish
- POJ 2503 Babelfish
- poj 2503 Babelfish【trie】
- 进程间通信之消息队列
- FileReference 类
- Git版本控制--tag标签的使用(二)
- Setup VPN connection (Microsoft PPTP) for Ubuntu 12.04
- 如何在 ASM 存储中使用 Data Pump (expdp impdp)进行数据导出导入操作
- hash Babelfish poj 2503
- C/C++代码格式优化工具----astyle
- SEAndroid策略
- POJ 1696/hrbustoj 1318 几何 蛋疼的蚂蚁
- ASIHTTPRequest类库简介和使用说明
- java的2道逻辑算法题
- C#中Winform动态调用Webservice的方法
- C#转义字符
- zookeeper分布式配置管理