poj2503字符串HASH
来源:互联网 发布:阿飞 傅红雪 知乎 编辑:程序博客网 时间:2024/05/16 10:35
HASH是一种极其有益的算法,俗称标记法,主要用途是从大量数据中找到某一些问题的答案。
和线段树差不多,不过线段树是搜寻相对应的量,而HASH则是一个单独的量。
比较有难度,而字符串HASH则是提高+的内容了,如果大家有兴趣的话,可以认真学习。
接下来是我编写的代码:
#include<stdio.h> #include<string.h> #include<stdlib.h> #define ull unsigned long long const ull p = 1e8+7; const int mod=100003; int e,to[mod],next[mod],begin[mod]; char a[mod][12],b[mod][12]; int hashx(char *s){ int len=strlen(s); ull hs=0; for(int i=0;i<len;i++) hs=hs*p+s[i]; return hs%mod+1; } void insert(int i,char *s){ int x=hashx(s); to[++e]=i; next[e]=begin[x]; begin[x]=e; } char *find(char *s){ int x=hashx(s); for(int i=begin[x];i;i=next[i]) if(strcmp(b[to[i]],s)==0) return a[to[i]]; return NULL; } int main(){ char s[15],s1[15],s2[15]; int i=0; while(1){ gets(s); if(s[0] == '\0') break; ++i; sscanf(s,"%s %s", a[i], b[i]); insert(i,b[i]); } while(gets(s)!=NULL){ if(s[0]=='\0')break; char *st=find(s); if(st!=0) puts(st); else puts("eh"); } return 0; }
1 1
- POJ2503 字符串HASH
- poj2503字符串HASH
- poj2503(字符串hash)
- poj2503 hash
- poj2503 简单的hash
- POJ2503 Babelfish(hash)
- poj2503 hash查找
- poj2503(简单hash)
- poj2503 Babelfish BKDRhash+链式hash
- poj2503查字典 -map或hash
- Babelfish(poj2503字符串处理)
- poj2503 二分查找字符串
- POJ2503 哈希(字符串编码)
- POJ2503
- poj2503
- poj2503
- POJ2503
- poj2503
- UE4:默认打开最近工程
- hiho第九十七周 数论六·模线性方程组
- HDU 5117 Fluorescent(期望+DP)
- unity源码解析Texture2D
- mybatis基础知识-1.JDBC存在的问题
- poj2503字符串HASH
- 第七届蓝桥杯—第三题||凑算式
- C程序实现图的邻接表表示
- 计算几何
- Program3_Q
- BZOJ 1600 建造栅栏
- 不惑JAVA之JAVA基础 - Set 和 List
- 《电路基础》反相运算放大器
- 从头认识多线程-2.15 解决由同步的synchronized (newobject()) 引起的脏读的方法