【题目链接】

http://poj.org/problem?id=2503

【算法】

字符串哈希

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 100010
typedef unsigned long long ULL;
const int P = ;
const int MOD = 1e5 + ; int i,tot,t;
ULL f[];
char s[],s1[MAXN][];
int nxt[MAXN],Head[MOD],d[MAXN];
char english[MAXN][];
char tmp; inline ULL get(char *s)
{
int i;
ULL ret = ;
for (i = ; i < strlen(s); i++) ret = ret * P + (s[i] - 'a' + );
return ret;
}
inline void Insert(ULL x,int p)
{
int pos = (int)(x % MOD);
tot++;
nxt[tot] = Head[pos];
d[tot] = p;
Head[pos] = tot;
}
inline void query(char *s)
{
int i;
ULL Hash = get(s);
int pos = (int)(Hash % MOD);
for (i = Head[pos]; i; i = nxt[i])
{
if (strcmp(s,s1[d[i]]) == )
{
printf("%s\n",english[d[i]]);
return;
}
}
printf("eh\n");
} int main()
{ f[] = ;
for (i = ; i <= ; i++) f[i] = f[i-] * P;
while (true)
{
t++;
if (t == ) scanf("%s%s",&english[t],&s1[t]);
else
{
english[t][] = tmp;
scanf("%s%s",&s,&s1[t]);
for (i = ; i < strlen(s); i++) english[t][i+] = s[i];
}
Insert(get(s1[t]),t);
getchar();
tmp = getchar();
if (tmp == '\n') break;
}
while (scanf("%s",&s) != EOF) query(s); return ; }

【POJ 2503】 Babelfish的更多相关文章

  1. 【POJ 2503】Babelfish(字符串)

    题 给定字典,再询问. 字典与询问之间有一个空行. cin.peek()是一个指针指向当前字符. #include<iostream> #include<string> #in ...

  2. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  3. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  4. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  5. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  6. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  7. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  8. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  9. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

随机推荐

  1. 输入一个链表,按链表值从尾到头的顺序返回一个ArrayList

    package algorithms; import java.util.ArrayList; import java.util.Stack; /** * public class ListNode ...

  2. Linux系统安装,组成及开关机

    Linux系统安装,组成及开关机 系统安装 swap分区用于实现虚拟内存,文件系统类型是swap. /分区用于存放包括系统程序和用户数据在内的所有数据,文件系统类型是ext4. 系统组成 Linux内 ...

  3. css3属性之-webkit-margin-before

    当没有对浏览器进行css边距初始化时,在web-kit浏览器上会出现下面的浏览器默认边距设置: ul, menu, dir { display: block; list-style-type: dis ...

  4. CentOS \Linux文件权限详解

    文件和目录权限概述 在linux中的每一个文件或目录都包含有访问权限,这些访问权限决定了谁能访问和如何访问这些文件和目录. 通过设定权限可以从以下三种访问方式限制访问权限:只允许用户自己访问:允许一个 ...

  5. buf.readFloatBE()

    buf.readFloatBE(offset[, noAssert]) buf.readFloatLE(offset[, noAssert]) offset {Number} 0 noAssert { ...

  6. 谈谈TCP中的TIME_WAIT

    所以,本文也来凑个热闹,来谈谈TIME_WAIT. 为什么要有TIME_WAIT? TIME_WAIT是TCP主动关闭连接一方的一个状态,TCP断开连接的时序图如下: 当主动断开连接的一方(Initi ...

  7. [spoj1182][Sorted Bit Sequence] (数位dp)

    Description Let's consider the 32 bit representation of all integers i from m up to n inclusive (m ≤ ...

  8. 聊聊餐饮: 2016年,是我做生意9年来,最差的1年 by某老板

    晚上忙完事,在小区里点了个菜.  今年在这个小店点菜,基本没有等过.  比较好奇,就问了下老板,最近怎么没人. 经常在这个店吃饭,老板就和我多聊了几句. 2016年,是我做生意9年来,最差的1年.还好 ...

  9. elasticsearch数据库使用

    elasticsearch的一个最为显著的优点:快速全文检索.关于elasticsearch 全文检索的原理,请看:https://blog.csdn.net/wolfcode_cn/article/ ...

  10. NYOJ35 表达式求值

    表达式求值 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 ACM队的mdd想做一个计算器,但是,他要做的不仅仅是一计算一个A+B的计算器,他想实现随便输入一个表达式 ...