【题目链接】

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. CAD隐藏或显示工具条上的按钮(com接口VB语言)

    主要用到函数说明: MxDrawXCustomFunction::Mx_HideToolBarControl 隐藏或显示工具条上的按钮.详细说明如下: 参数 说明 IN LPCTSTR pszTool ...

  2. 作业 3-5 switch语句的应用

    /*输入五级制成绩(A-E),输出相应的百分制成绩(0-100)区间*/ #include<stdio.h> int main(void) { char ch;/*定义一个字符*/ pri ...

  3. ubuntu 常见的操作命令

    原博客地址为:https://blog.csdn.net/qq_33421080/article/details/76551554 1.cd命令: cd:切换到当前用户根目录,默认[/home/用户名 ...

  4. Python学习——集合

    集合 python中的集合和数学上集合具有基本相同的性质,此处不再赘述. 1.创建集合的两种方法 #直接创建 num={1,2,3,4,5} #利用set方法创建 num1=set([1,2,3,4, ...

  5. 洛谷 1097 统计数字(NOIp2007提高组T1)

    [题解] 排个序然后扫一遍进行统计即可. #include<cstdio> #include<algorithm> #include<cstring> #defin ...

  6. codechef营养题 第三弹

    第三弾が始まる! codechef problems 第三弹 一.Motorbike Racing 题面 It's time for the annual exciting Motorbike Rac ...

  7. EasyUI Datagrid的简单使用

    此前同样写过EasyUI Datagrid的demo,好记性不如烂笔头,何况记性也不是那么好,赶紧记录一下.照搬上一篇EasyUI Tree的格式. 实现效果:获取数据库表的数据,在EasyUI Da ...

  8. mybatis example 排序 语句

    mybatis example 排序 语句 IntegralInfoExample integral = new IntegralInfoExample(); integral.createCrite ...

  9. Ubuntu16.04再次装机记

    个人的吐槽 整个国庆假期(9天),基本上都在搭建PHP环境中耗费了. 是这样的——来大学报到前,想着大学里用个Dev-C++应该够了,于是把Ubuntu删了,腾出了100G的空间.到了CSU,加了团委 ...

  10. HUD——1286 找新朋友

    思路: 裸的欧拉函数 代码: #include<cstdio> #include<cstring> #include<cstdlib> #include<io ...