【题目链接】

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. Pycharm 专业版安装

    1.Pycharm官网,网址:http://www.jetbrains.com/pycharm/download/#section=windows,下载PyCharm安装包,根据自己电脑的操作系统进行 ...

  2. 00Enterprise Resource Planning

    Enterprise Resource Planning         企业资源计划即 ERP (Enterprise Resource Planning),由美国 Gartner Group 公司 ...

  3. 第三节:执行一些EF的增删改查

    针对两表操作 一丶增加 #region 05-增加操作 /// <summary> /// 05-增加操作 /// </summary> /// <param name= ...

  4. python实现给定一个数和数组,求数组中两数之和为给定的数

    给定一个整数数组和一个目标值,找出数组中和为目标值的两个数.你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用. 示例: 给定 nums = [2, 7, 11, 15], target = ...

  5. Linux学习笔记(七) 查询系统

    1.查看命令 (1)man 可以使用 man 命令名称 命令查看某个命令的详细用法,其显示的内容如下: NAME:命令名称 SYNOPSIS:语法 DESCRIPTION:说明 OPTIONS:选项 ...

  6. radis入门

    redis介绍 是远程的,有客户端.服务端 存内存,吃内存 应用场景 缓存 队列 list操作 push pop 数据存储[根据redis硬盘持久化的机制,这里不展开] 5种数据类型 string 字 ...

  7. 洛谷 1071 潜伏者(NOIp2009提高组)

    [题意概述] 给出三行字符串,前两行代表密码与明文的对应关系,第三行为待翻译的文本.要求按照对应关系翻译文本. [题解] 直接模拟即可. 注意判断Failed的情况. #include<cstd ...

  8. 多校1007 Naive Operations

    >>点击进入原题测试<< 思路:好像是第一次这么印象深刻的写线段树,说实话,这个题确实很有意思,值得学习. 看了大神讲解视频,但是自己写的还是超时了. 参考来自 https:/ ...

  9. springcloud(九):熔断器Hystrix和Feign的应用案例

    因为 feign 中已经支持了 Hystrix ,所以在 Feign 中使用 Hystrix 时,不需要导包,也不需要在入口类上面增加额外的注解:  Feign 虽然支持了 Hystrix ,但是默认 ...

  10. 设置mysql5.7远程连接-----------https://blog.csdn.net/qiyueqinglian/article/details/52778230

    https://blog.csdn.net/qiyueqinglian/article/details/52778230 设置mysql5.7远程连接