【POJ 2503】 Babelfish
【题目链接】
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的更多相关文章
- 【POJ 2503】Babelfish(字符串)
题 给定字典,再询问. 字典与询问之间有一个空行. cin.peek()是一个指针指向当前字符. #include<iostream> #include<string> #in ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
随机推荐
- CAD与用户交互在图面上选择一个实体(com接口VB语言)
主要用到函数说明: IMxDrawUtility::GetEntity 与用户交互到在图面上选择一个实体,详细说明如下: 参数 说明 [out] IMxDrawPoint** pPickPoint 返 ...
- 带返回值的线程Callable
- 个人总结的常用java,anroid网站
http://blog.csdn.net/wanghao200906/article/details/49334987
- python lambda简易使用
基本格式 lambda 变量名:函数表达式 ①直接使用 f=lambda x:x**2 f(3) ②设置函数列表 l=[lambda x:x**2, lambda x:x**3, lambda x:x ...
- <SpringMvc>入门二 常用注解
1.@RequestMapping @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME ...
- Python学习-字符串的基本知识
字符串的基本知识 根据所展示形式的不同,字符串也可以分为两类 原始字符串: 使用单引号包括:‘liuwen’ 使用双引号包括:"liuwen" 使用3个单引号包括 :'''liuw ...
- MongoDB怎么快速的删除数据库数据?
我的mongodb里有10+数据库.现在需要重置这个环境,得到干净的没有数据的MongoDB.怎么快速安全的删除这些数据库数据呢? 记得首先备份你的数据库mongodump -o bakfolder ...
- noip模拟赛 立方数2
题目描述LYK定义了一个数叫“立方数”,若一个数可以被写作是一个正整数的3次方,则这个数就是立方数,例如1,8,27就是最小的3个立方数.LYK还定义了一个数叫“立方差数”,若一个数可以被写作是两个立 ...
- python函数基础:嵌套函数、作用域、匿名函数、高阶函数、递归函数
嵌套函数: 1. 函数内部可以再定义函数 2. 函数只有被调用之后才会执行 看如下代码: age = 18 def func1(): age = 22 print(age) def func2(): ...
- 26、Java并发性和多线程-线程池
以下内容转自http://ifeve.com/thread-pools/: 线程池(Thread Pool)对于限制应用程序中同一时刻运行的线程数很有用.因为每启动一个新线程都会有相应的性能开销,每个 ...