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 题意:略 思路: 一开始就是想到了正确的思路,但是代码写炸了,死活过不了.这题嘛,就是建议一个魔咒与咒语的双向映射.首先用字符串 ...
随机推荐
- (剑指Offer)面试题17:合并两个排序的链表
题目: 输入两个递增排序的链表,合并这两个链表并使新链表中的结点仍然时按照递增排序的. 链表结点定义如下: struct ListNode{ int val; ListNode* next; }; 思 ...
- Oracle数据库定时任务配置和日志执行情况查询
基础配置: /***************************************************************** * * 移动抵扣券快到期推送提醒 * 首次执行 : 2 ...
- StringUtils 字符串工具类
package com.thinkgem.jeesite.common.utils; import java.io.File; import java.io.IOException; import j ...
- SiteMesh学习入门
http://www.java3z.com/cwbwebhome/article/article2/2962.html?id=1668 demo下载 简介: sitemesh应用Decorat ...
- Angular JS 使用的注意事项
标签中ng-app,什么情况需要指定名称,什么时候又不需要呢? 1.ng-app="" <div ng-app="" ng-controller='myC ...
- Java中String对象的不可变性
首先看一个程序 package reverse; public class Reverse { public static void main(String[] args) { String c1=n ...
- 【转】selenium及webdriver的原理
主要内容转自:http://blog.csdn.net/ant_ren/article/details/7968582和http://blog.csdn.net/ant_ren/article/det ...
- sql注入在线检測(sqlmapapi)
之前一搞渗透的同事问我.sqlmapapi.py是干啥的,我猜非常多人都玩过sqlmap,但玩过sqlmapapi的应该比較少,今天就和大家一起看看怎样使用以及一些美的地方. 说白了.sqlmapap ...
- EasyUI-在iframe里获取现阶段选中的tab的标题
在iframe里获取当前选中的tab的标题(easyui) var currTab =$$('#tabs').tabs('getSelected'); console.info(currTab.pan ...
- ztree使用心得
一个很好用的Jquery树形控件 官网:http://www.ztree.me/v3/main.php#_zTreeInfo 我主要引用的文件为: //最新版的JS压缩包 <script src ...