uva 10282 - Babelfish
来源:互联网 发布:数据精灵破解版 编辑:程序博客网 时间:2024/05/24 02:00
这题可以用map直接水过,但是那样就没有什么意思了。
所以还是用hash表写了下,学习了一下hash链表的方法,其实就是做一个邻接表,但是这样在判断时还要比较生成hash值的string,而且如果hash函数没构造好,复杂度会大大增加,不过是一个解决冲突的好办法。
/*author:jxylang:C/C++university:China,Xidian University**If you need to reprint,please indicate the source***/#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <stdlib.h>#define INF 1E9using namespace std;int head[1000000],next[100010];string s[100010],f[100010];int get_hash(string s){ long long ans=0; for(int i=0;i<s.size();i++) ans=ans*33+s[i]; return ans%999991;}int main(){ memset(head,-1,sizeof(head)); string a,t; char ss; int cnt=1,now,u; s[0]="eh"; while(cin>>a>>t) { s[cnt]=a; f[cnt]=t; now=get_hash(t); next[cnt]=head[now];//因为数据保证唯一,所以直接插入即可 head[now]=cnt; cnt++; getchar(); if((ss=getchar())=='\n')break;//判断有无遇到空行 else ungetc(ss,stdin); } while(cin>>a) { now=get_hash(a); bool flag=1; for(u=head[now];u!=-1;u=next[u]) { if(f[u]!=a)continue; cout<<s[u]<<endl; flag=0; } if(flag)cout<<s[0]<<endl; }}
- UVa 10282 - Babelfish
- uva 10282 - Babelfish
- uva 10282 - Babelfish
- uva-10282 - Babelfish
- uva 10282 - Babelfish
- UVA 10282 Babelfish
- UVa 10282 - Babelfish
- UVA 10282 - Babelfish
- UVA 10282 Babelfish
- uva 10282 Babelfish
- UVA 10282 - Babelfish
- UVa 10282 - Babelfish
- UVA - 10282 Babelfish
- uva 10282 Babelfish
- uva 10282 Babelfish
- UVA - 10282 Babelfish
- uva 10282 Babelfish(STL map)
- [二分查找]Babelfish uva 10282
- swfupload jsp入门指南
- A Sample Linker Script
- 寒假前刷题(7)搜索系列 dfs hdu 1010
- IBM Key Management工具(iKeyMan)脚本吃掉%*$*无法接收命令行参数之解
- 关于几个指针的问题
- uva 10282 - Babelfish
- Bootloader移植简述
- Qt 学习之路 2(3):Hello, world!
- Python的elif语句
- 大数加法模板(c++)
- uboot命令大全 --来源于网络(ChinaUnix)
- PS2接口和协议
- 【Android游戏开发之六】在SurfaceView中添加系统控件,并且相互交互数据!
- vim 插件——浏览器