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 题意:略 思路: 一开始就是想到了正确的思路,但是代码写炸了,死活过不了.这题嘛,就是建议一个魔咒与咒语的双向映射.首先用字符串 ...
随机推荐
- 移动端翻页插件dropload.js(支持Zepto和jQuery)
一. 声明 代码来源:github上的dropload项目. 二. 问题 dropload.js提供了最基本的上拉翻页,下拉刷新功能.对于由服务端一次返回所有数据的情况基本通用. 但是,需求往往不是服 ...
- $(document).ready()与 window.onload执行时机
$(document).ready()方法和window.onload方法有相似的功能,但是在执行时机方面是有区别的.window.onload方法是子啊网页中的所有元素(包括元素的所有关联的文件)完 ...
- pycharm快捷键大全
Python IDE PyCharm的快捷键大全1.编辑(Editing)Ctrl + Space 基本的代码完成(类.方法.属性)Ctrl + Alt + Space 快速导入任意类Ctrl + S ...
- java.util.Date转java.sql.Date丢失时间问题
java.sql.Date 只存储日期数据不存储时间数据// 会丢失时间数据preparedStatement.setDate(1, new java.sql.Date(date.getTime()) ...
- 关于Javascript的内存泄漏问题的整理稿
写了好长时间javascript小功能模块,从来没有关注过内存泄漏问题.记得以前写C++程序的时候,内存泄漏是个严重的问题,我想是时候关注一下了.网上找了篇文章,Mark一下.原文地址:http:// ...
- 模拟log4j获取日志对象调用所在的类名、方法名及行号
当我们在记录日志时,每个类中会定义一个日志对象,然后利用这个对象去写日志,那么我们在处理日志时,如何能才能记录日志对象所在的类.方法和行号呢?log4j中已经实现了该功能,那么它是怎么实现的呢? 其实 ...
- C语言(1+1+2+1+2+3....+n)
#include<stdio.h> void main(){ int i,j,a; long sum=0; //输入a的值 scanf("%d",&a); if ...
- LFS7.4编译笔记(3)
在第一部分,我们编译了一个工具链及临时系统,然后在第二部分我们chroot到/mnt/lfs下面,利用临时系统的工具编译了我们最终的LFS系统.不过此时,我们的LFS系统还是不完整的,因为我们还没有安 ...
- 使用贝赛尔曲线画扇形、圆形、弧线、多边形,实现App下载时的动画效果demo
// // MyView.swift // TestUIBezierPath // // Created by iCodeWoods on 16/5/8. // Copyright © 2016年 i ...
- Blob未完成(待优化)
/**************************************************/ /* Author : Anby */ /* Using :兼容powerBuilder中的B ...