题目链接:http://poj.org/problem?id=2503

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> using namespace std; const int maxn = ;
const int HASH = ; int head[HASH],next[maxn];
char s1[maxn][],s2[maxn][];
int n; int hash(char *s)
{
int ret = ;
int seed = ;
while(*s)
{
ret = ret * seed + *(s++);
}
return (ret & 0x7fffffff) % HASH;
} int search(char *s)
{
int i;
int id = hash(s);
for(i=head[id]; i!=-; i=next[i])
{
if(strcmp(s,s2[i]) == )
break;
}
return i;
} void input()
{
memset(head,-,sizeof(head));
n = ;
char ch[];
gets(ch);
while(ch[] != '\0')
{
int i=,j;
for(i=,j=; ch[i]!=' '; i++,j++)
s1[n][j] = ch[i];
s1[n][j] = '\0';
i++;
for(j=; ch[i]!='\0'; i++,j++)
s2[n][j] = ch[i];
s2[n][j] = '\0'; int id = hash(s2[n]);
next[n] = head[id];
head[id] = n;
n++;
gets(ch);
}
} void solve()
{
char ch[];
while(scanf("%s",ch) == )
{
int id = search(ch);
if(id == -)
{
printf("eh\n");
}
else
{
printf("%s\n",s1[id]);
}
}
}
int main()
{
// freopen("E:\\acm\\input.txt","r",stdin);
input();
solve();
}

poj 2503 字符串hash的更多相关文章

  1. POJ 1200 字符串HASH

    题目链接:http://poj.org/problem?id=1200 题意:给定一个字符串,字符串只有NC个不同的字符,问这个字符串所有长度为N的子串有多少个不相同. 思路:字符串HASH,因为只有 ...

  2. poj 1200字符串hash

    题意:给出不同字符个数和子串长度,判断有多少个不同的子串 思路:字符串hash. 用字符串函数+map为什么会超时呢?? 代码: #include <iostream> #include ...

  3. poj 2503(字符串)

    http://poj.org/problem?id=2503 题意:就是翻译,给你一个字典,然后再查找单词,找得到的就输出单词,找不到的输出eh,用Map水题一个,但这个题有点意思的就是输入的问题 # ...

  4. 字符串hash + 二分答案 - 求最长公共子串 --- poj 2774

    Long Long Message Problem's Link:http://poj.org/problem?id=2774 Mean: 求两个字符串的最长公共子串的长度. analyse: 前面在 ...

  5. POJ 3865 - Database 字符串hash

    [题意] 给一个字符串组成的矩阵,规模为n*m(n<=10000,m<=10),如果某两列中存在两行完全相同,则输出NO和两行行号和两列列号,否则输出YES [题解] 因为m很小,所以对每 ...

  6. POJ 1743 Musical Theme (字符串HASH+二分)

    Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 15900   Accepted: 5494 De ...

  7. poj 3461 字符串单串匹配--KMP或者字符串HASH

    http://poj.org/problem?id=3461 先来一发KMP算法: #include <cstdio> #include <cstring> #include ...

  8. 字符串hash - POJ 3461 Oulipo

    Oulipo Problem's Link ---------------------------------------------------------------------------- M ...

  9. Palindrome POJ - 3974 (字符串hash+二分)

    Andy the smart computer science student was attending an algorithms class when the professor asked t ...

随机推荐

  1. SQL优化(2)

    建表时候数据库引擎的选择也可以达到优化的效果 InnoDB: 基于磁盘的资源是InnoDB表空间数据文件和它的日志文件,InnoDB 表的大小只受限于操作系统文件的大小,一般为 2GB MyISAM: ...

  2. 深入了解overflow

    1.如果overflow-x与overflow-y值不同   其中一个赋值为visiable,另一个赋值scroll/auto/hidden,那么visiable会重置为auto 2.overflow ...

  3. 降低IIScup使用率,提高性能

    智能提醒webservice在高峰期间CPU使用率达到50%,内存消耗2G优化方法:启用IIS的Web Garden. 步奏如下: 在IIS7中,选择对应的应用程序池 然后右键高级设置. 把其中的最大 ...

  4. pdo如何防止 sql注入

    我们使用传统的 mysql_connect .mysql_query方法来连接查询数据库时,如果过滤不严,就有SQL注入风险,导致网站被攻击,失去控制.虽然可以用 mysql_real_escape_ ...

  5. php验证复选框有效性的示例

    本文介绍一个简单的php通过代码验证复选框值的有效性,有需要的可以参考一下 验证复选框的php代码,如下: 复制代码代码如下: <?php   /**   * 在php中验证复选框的有效性  * ...

  6. php中getimagesize函数的用法

    php获取图片信息getimagesize,php自带函数.获取图片的类型,尺寸的方法有许多,该函数仅是方法之一. getimagesize() 函数将测定任何 GIF,JPG,PNG,SWF,SWC ...

  7. jinja2 宏的简单使用总结(macro)

    Table of Contents 1. 简介 2. 用法 3. 参数和变量 4. 注意事项 4.1. macro的变量只能为如下三种: 4.2. 和block的关系: 5. 参考文档 1 简介 ji ...

  8. [swift]可选类型

    可选类型 <Swift权威指南>第2章千里之行始于足下——Swift语言基础,本章挑选了Swift语言的最基本特性加以介绍.尽管这些特性只占Swift全部特性的很少一部分,但却是所有的Sw ...

  9. 国内物联网平台初探(八):移动云OneNET

    国内物联网平台初探(八)——移动云OneNET 平台架构 数据模型 使用场景示意图 服务 IOT Paas 基础服务 为IoT开发者提供智能设备自助开发工具.后台技术支持服务,为您提供物联网专网.短彩 ...

  10. 关于回波损耗 和 驻波比的摘要 Return Loss and VSWR

    关于回波损耗 和 驻波比的摘要 以下摘自:http://www.soontai.com/cal_rtvswr.html RL = 20log((VSWR+1) / (VSWR-1)) VSWR = ( ...