【题目链接】

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. 并发和多线程(六)--ThreadLocal

    ThreadLocal是什么? 当使用ThreadLocal修饰变量的时候,ThreadLocal会为每个使用该变量的线程提供独立的变量副本,每个线程可以独立改变自己的副本,而不 影响其他线程的变量副 ...

  2. datetimebox赋值或取值

    datetimebox赋值或取值 $('#j_dateStart').datebox('setValue', ""); //赋予空值 $("#j_dateStart&qu ...

  3. ProgressDialog的样式

    ProgressDialog的样式有两种,一种是圆形不明确状态,一种是水平进度条状态 第一种方式:圆形进度条 final ProgressDialog dialog = new ProgressDia ...

  4. 干货分享--iOS及Mac开源项目和学习资料【超级全面】

    原文出处:codecloud http://www.kancloud.cn/digest/ios-mac-study/84557

  5. 洛谷——P3811 【模板】乘法逆元

    P3811 [模板]乘法逆元 线性求逆元 逆元定义:若$a*x\equiv1 (\bmod {b})$,且$a$与$b$互质,那么我们就能定义: $x$为$a$的逆元,记为$a^{-1}$,所以我们也 ...

  6. UVA - 1618 Weak Key(RMQ算法)

    题目: 给出k个互不相同的证书组成的序列Ni,判断是否存在4个证书Np.Nq.Nr.Ns(1≤p<q<r<s≤k)使得Nq>Ns>Np>Nr或者Nq<Ns&l ...

  7. keepalived(nginx的高可用)安装文档

    1. 安装环境 su - root yum -y install kernel-devel* yum -y install openssl-* yum -y install popt-devel yu ...

  8. php利用32进制实现对id加密解密

    前言 最近在项目中遇到一个问题,当前用户分享一个邀请码给好友,好友根据邀请码注册成为新用户之后,则成为当前用户的下级,特定条件下,可以得到下级用户的一系列返利.这里要实现的就是根据当前用户的id,生成 ...

  9. vue子组件向父组件传递参数的基本方式

    子组件: this.$emit('transferUrl', this.picUrl) 父组件: 引入子组件<pics @transferUrl="gettransferUrl&quo ...

  10. 离职 mark

    昨天(2019 年 5 月 17 日),从 离职. 从 2018 年 7 月 14 日早 10 点余分到 2019 年 5 月 17 日早 10 点余分,一共 308 天整.这就是我出学校的第一份工作 ...