hdu1880
魔咒词典
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12387 Accepted Submission(s): 3022
给你一部魔咒词典。当哈利听到一个魔咒时,你的程序必须告诉他那个魔咒的功能;当哈利需要某个功能但不知道该用什么魔咒时,你的程序要替他找到相应的魔咒。如果他要的魔咒不在词典中,就输出“what?”
[魔咒] 对应功能
其中“魔咒”和“对应功能”分别为长度不超过20和80的字符串,字符串中保证不包含字符“[”和“]”,且“]”和后面的字符串之间有且仅有一个空格。词典最后一行以“@END@”结束,这一行不属于词典中的词条。
词典之后的一行包含正整数N(<=1000),随后是N个测试用例。每个测试用例占一行,或者给出“[魔咒]”,或者给出“对应功能”。
[rictusempra] send a jet of silver light to hit the enemy
[tarantallegra] control the movement of one's legs
[serpensortia] shoot a snake out of the end of one's wand
[lumos] light the wand
[obliviate] the memory charm
[expecto patronum] send a Patronus to the dementors
[accio] the summoning charm
@END@
4
[lumos]
the summoning charm
[arha]
take me to the sky
accio
what?
what?
无意中看到这题,就切了一下,感觉这题很适合刚刚接触散列表和字符串处理的朋友,直接对字符串hash就可以了,用map会MlE。
AC代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int MAX=;
const int mod=;
struct Node{
Node* ne;
char st[];
}haxi[MAX],*h[mod],*cur;
unsigned int BKDHash(char* s){
unsigned int seed=;
unsigned int ret=;
while(*s) ret=ret*seed+*s++;
return (ret&0x7FFFFFFF)%mod;
}
int getId(char* s){
int code=BKDHash(s);
Node* ptr=h[code];
while(ptr){
if(strcmp(ptr->st,s)==)
return ptr-haxi;
else
ptr=ptr->ne;
}
strcpy(cur->st,s);
cur->ne=h[code];
h[code]=cur++;
return cur-haxi-;
}
int find(char* s){
int code=BKDHash(s);
Node* ptr=h[code];
while(ptr){
if(strcmp(ptr->st,s)==){
return ptr-haxi;
}else{
ptr=ptr->ne;
}
}
return -;
}
int main(){
char s[],*p;
int id,n;
cur=haxi;
memset(h,,sizeof(h));
while(scanf("%s",s),s[]!='@'){
getId(s);
getchar();
gets(s);
getId(s);
}
scanf("%d",&n);
gets(s);
while(n--){
gets(s);
id=find(s);
if(id==-){
puts("what?");
}else{
p=haxi[id^].st;
if(p[]!='[') puts(p);
else{
p++;
while(*p!=']'){
putchar(*p++);
}
puts("");
}
}
}
return ;
}
hdu1880的更多相关文章
- C++之路进阶——HDU1880(魔咒词典)
---恢复内容开始--- New~ 欢迎参加2016多校联合训练的同学们~ 魔咒词典 Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 3 ...
- 魔咒词典--hdu1880(字符串 暴力)
http://acm.hdu.edu.cn/showproblem.php?pid=1880 不要想其他的 暴力就能过 #include <iostream> #include < ...
- HDU1880 魔咒词典
题目大意:对应的输入多行,每行两个字符串,两个字符串互相映射.接下来询问的时候,如果这个字符串出现过,输出其对应的字符串. 分析:二重哈希来判断字符串是否存在,输出其对应的字符串就行.二重哈希的入门题 ...
- hdu 1880 魔咒字典
https://vjudge.net/problem/HDU-1880 题意:略 思路: 一开始就是想到了正确的思路,但是代码写炸了,死活过不了.这题嘛,就是建议一个魔咒与咒语的双向映射.首先用字符串 ...
随机推荐
- 番茄钟App(Pomodoro Tracker)
最近为了学习Swift编程语言,写了一个番茄钟的App(Pomodoro Tracker).刚上线的1.2版本增加了Apple Watch的支持. iPhone版 Apple Watch版 如果你跟我 ...
- Slony-I中对storelisten出错的处理
客户质询的现象是: Slony-I运行中,log中发现FATAL信息: FATAL storeListen: unknown node ID 出现了上述错误后,再看后继的log,又恢复正常运行了. 客 ...
- Codeforces Gym 100231L Intervals 数位DP
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description Start with an integer, N0, ...
- JavaScript模块化开发一瞥
对于那些正在构建大型应用程序,而对JavaScript不甚了解的开发者而言,他们最初必须要面对的挑战之一就是如何着手组织代码.起初只要在标记之间嵌入几百行代码就能跑起来,不过很快代码就会变得一塌糊涂… ...
- 【JavsScript】webapp的优化整理
单页or多页 webapp 现状 优劣之分 网络传输优化 综述 fake页-首屏加速 降低请求数 降低请求量 缓存Ajax/localstorage DOM操作优化 综述 关于页面渲染 减少使用定位属 ...
- Citrix 服务器虚拟化之二十八 XenApp6.5发布文档内容
Citrix 服务器虚拟化之二十八 XenApp 6.5发布文档内容 XenApp可发布以下类型的资源向用户提供信息访问,这些资源可在服务器或桌面上虚拟化: 1) 服务器桌面:发布场中服务器的整个 ...
- MyBatis学习练习
转自:http://ccchhhlll1988-163-com.iteye.com/blog/1415621 基本目的:利用Mybatis完成对一个表简单的select.insert.update.d ...
- scala命令
1. intersect方法找出两个字符串的相同字符: scala> "Hello".intersect("World") res3: String = ...
- lua分割字符串终究版(转载,有改动)
来源http://codepad.org/BRHIS6WA --根据首字节获取UTF8需要的字节数 local function GetUTF8CharLength(ch) local utf8_lo ...
- 项目源码--Android天气日历精致UI源码
下载源码 技术要点: 1. 天气日历精致UI 2. Android的Http通信技术 3. Android的天气信息解析 4. Android的日历信息的统计 5. Andorid的地理位置的管理 6 ...