题目大意:对应的输入多行,每行两个字符串,两个字符串互相映射。接下来询问的时候,如果这个字符串出现过,输出其对应的字符串。

分析:二重哈希来判断字符串是否存在,输出其对应的字符串就行。二重哈希的入门题,字符串还挺有意思的。

代码:

#include<iostream>
#include<string>
#include<map>
#include<string>
using namespace std;
typedef unsigned long long ull;
map<pair<int,int>,string> dict;
const int s1=,s2=;
const int maxn=1e5+;
char s[],t[];
int hash1(char* s){
int ans=;
for(int i=;s[i];i++)
ans=(ans*s1+s[i])%maxn;
return ans;
}
int hash2(char* s){
int ans=;
for(int i=;s[i];i++)
ans=(ans*s2+s[i])%maxn;
return ans;
}
void read(){
int cnt=;
while(scanf("%s",s)&&s[]!='@'){
getchar();
cnt=;
while((t[cnt]=getchar())!='\n')
cnt++;
t[cnt]='\0';
dict[make_pair(hash1(s),hash2(s))]=t;
dict[make_pair(hash1(t),hash2(t))]=s;
}
}
void solve(){
int m,x,y,cnt=;
scanf("%d",&m);
getchar();
while(m--){
cnt=;
while((s[cnt]=getchar())!='\n')
cnt++;
s[cnt]='\0';
x=hash1(s);
y=hash2(s);
if(s[]=='['){
if(dict.find(make_pair(x,y))==dict.end()) printf("what?\n");
else cout<<dict[make_pair(x,y)]<<endl;
}
else{
if(dict.find(make_pair(x,y))==dict.end()) printf("what?\n");
else cout<<dict[make_pair(x,y)].substr(,dict[make_pair(x,y)].length()-)<<endl;
}
}
}
int main(){
read(); solve(); return ;
}

HDU1880 魔咒词典的更多相关文章

  1. C++之路进阶——HDU1880(魔咒词典)

    ---恢复内容开始--- New~ 欢迎参加2016多校联合训练的同学们~ 魔咒词典 Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 3 ...

  2. HDU 1880 魔咒词典(字符串哈希)

    题目链接 Problem Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一 ...

  3. hdu 1880 魔咒词典

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1880 魔咒词典 Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有10 ...

  4. HDU 1880 魔咒词典 (Hash)

    魔咒词典 Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. 题目1029:魔咒词典(map使用以及字符串读取函数总结)

    题目链接:http://ac.jobdu.com/problem.php?pid=1029 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus // // ...

  6. hdu 1880 魔咒词典 (字符串哈希)

    魔咒词典 Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. ACM1880魔咒词典

    魔咒词典 Problem Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一 ...

  8. HDU - 1880 魔咒词典~哈希入门

    哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮助. 给你一部魔咒词 ...

  9. 九度OJ 1029:魔咒词典 (排序)

    时间限制:5 秒 内存限制:32 兆 特殊判题:否 提交:4574 解决:1318 题目描述:     哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部 ...

随机推荐

  1. codeforces- Shortest path of the king

    The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, becaus ...

  2. 用apt-get解决dpkg过程中出现的依赖问题

    dpkg命令不解决依赖问题,这点对新手很不友好 当使用dpkg -i *.deb 安装出现依赖问题的时候,可以尝试如下解决方法: apt-get -f -y install # 复制粘贴回车,inst ...

  3. nginx、apache和tomcat之间的关系和区别

    Apache/Nginx 应该叫做 HTTP Server,即安装后生成httpd服务. Tomcat 则是一个 Application Server,或者更准确的来说,是一个「Servlet/JSP ...

  4. java编译中出现了Exception in thread “main" java.lang.UnsupportedClassVersionError

    这个问题确实是由较高版本的JDK编译的java class文件试图在较低版本的JVM上运行产生的错误. 1.解决措施就是保证jvm(java命令)和jdk(javac命令)版本一致.如果是linux版 ...

  5. Python之字符(2)

    1.string.issupper()表示判断字符是否全部为小写字母. string1 = "abcdef" string2 = "ABCdef" string ...

  6. 一 Spring概述

    知识点概要: 1 SpringIOC入门(XML).Spring的Bean管理.Spring属性注入 2 SpringIOC注解方式.Spring的AOP开发(XML) 3 Spring的AOP注解开 ...

  7. Java 8 有哪些新特性

    一.支持 lambda 表达式 例如:查询学生信息,并打印 List<Student> studentList = Student.findAllStudent(); for(Studen ...

  8. Excel使用小技巧

    1.Excel随机设置单元格的内容为整数0或1: 在单元格中写公式:  =ROUND(RAND(),0) 2.设置某个单元格的值为1或0,根据其他3个单元格的值为0或1来确定: 在该单元格中写公式: ...

  9. 纪录片 - Why Are We Fat?(全3集)

    1. 传送门:https://www.bilibili.com/video/av13977351?spm_id_from=333.338.__bofqi.16 2. 笔记 第一型糖尿病是天生的,第二型 ...

  10. MyBatis模糊查询异常: '%${}''读取jdbc属性

    '%${}''总是传root, 后来发现${username}读取了jdbc里面的属性username,于是将jdbc属性名修改,成功