ACM1880魔咒词典
魔咒词典
给你一部魔咒词典。当哈利听到一个魔咒时,你的程序必须告诉他那个魔咒的功能;当哈利需要某个功能但不知道该用什么魔咒时,你的程序要替他找到相应的魔咒。如果他要的魔咒不在词典中,就输出“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?
- #include<iostream>
- #include<cstring>
- using namespace std;
- class Alphabet
- {
- public:
- char sign[],power[];
- Alphabet *next;
- };
- class Process
- {
- public:
- Process()
- {
- head=NULL;
- p=NULL;
- record=NULL;
- }
- void Input()
- {
- char sh[];
- char s1[],s2[];
- while(gets(sh)&&(strcmp(sh,"@END@")!=))
- {
- char *ch=strchr(sh,']');
- ch+=;
- int i;
- for( i=;sh[i]!=']';i++)
- {
- s1[i]=sh[i];
- }
- s1[i]=sh[i];
- s1[i+]=;
- Insert(s1,ch);
- }
- scanf("%d",&num);getchar();
- for(int i=;i<=num;i++)
- {
- char s[];
- gets(s);
- if(s[]=='[')
- SearchSign(s);
- else
- SearchPower(s);
- }
- }
- void SearchSign(char *s)
- {
- p=head;
- while(p!=NULL)
- {
- if(strcmp(p->sign,s)==)
- {
- printf("%s\n",p->power);
- return;
- }
- p=p->next;
- }
- printf("what?\n");
- }
- void SearchPower(char *s)
- {
- p=head;
- while(p!=NULL)
- {
- if(strcmp(p->power,s)==)
- {
- int n=strlen(p->sign);
- for(int i=;i<n-;i++)
- {
- printf("%c",p->sign[i]);
- }
- printf("\n");
- return;
- }
- p=p->next;
- }
- printf("what?\n");
- }
- void Insert(char *s1,char *s2)
- {
- p=new Alphabet;
- strcpy(p->sign,s1);
- strcpy(p->power,s2);
- if(head==NULL)
- head=p;
- else
- record->next=p;
- record=p;
- record->next=NULL;
- }
- void OUTPUTALL()
- {
- p=head;
- while(p!=NULL)
- {
- cout<<p->sign<<" "<<p->power<<endl;
- p=p->next;
- }
- //printf("what?\n");
- }
- private:
- int num;
- Alphabet *head,*p,*record;
- };
- int main()
- {
- while()
- {
- Process p1;
- p1.Input();
- }
- return ;
- }
[expelliarmus] the disarming charm
[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@
8
[lumos]
the summoning charm
[arha]
take me to the sky
the memory charm
send a Patronus to the dementors
[tarantallegra]
send a jet of silver light to hit the enemy
我所提交的代码和这个不同,需要将类撤掉,把输入放到主函数里,不然无法结束,但是整体算法不变;
ACM1880魔咒词典的更多相关文章
- C++之路进阶——HDU1880(魔咒词典)
---恢复内容开始--- New~ 欢迎参加2016多校联合训练的同学们~ 魔咒词典 Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 3 ...
- HDU 1880 魔咒词典(字符串哈希)
题目链接 Problem Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一 ...
- hdu 1880 魔咒词典
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1880 魔咒词典 Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有10 ...
- HDU 1880 魔咒词典 (Hash)
魔咒词典 Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 题目1029:魔咒词典(map使用以及字符串读取函数总结)
题目链接:http://ac.jobdu.com/problem.php?pid=1029 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus // // ...
- hdu 1880 魔咒词典 (字符串哈希)
魔咒词典 Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU - 1880 魔咒词典~哈希入门
哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮助. 给你一部魔咒词 ...
- 九度OJ 1029:魔咒词典 (排序)
时间限制:5 秒 内存限制:32 兆 特殊判题:否 提交:4574 解决:1318 题目描述: 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部 ...
- 九度oj 题目1029:魔咒词典
题目描述: 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮 ...
随机推荐
- 你真的了解JAVA里的String么
Java中String类细节问题 (考察点Java内存分配问题) 1. String str1 = "abc"; System.out.println(str1 == &quo ...
- Spring Security 快速了解
在Spring Security之前 我曾经使用 Interceptor 实现了一个简单网站Demo的登录拦截和Session处理工作,虽然能够实现相应的功能,但是无疑Spring Security提 ...
- NSTimer使用注意事项
1.scheduled开头和非schedule的开头方法的区别.系统框架提供了几种创建NSTimer的方法,其中以scheduled开头的方法会自动把timer加入当前run loop,到了设定的时间 ...
- javabean的内省技术和BeanUtils的使用
一.关于javabean javabean是固定写法的java类 书写格式为: 1)必须有无参构造函数 2)属性必须私有, 我们称为字段 3)提供标准的getter和setter 例: name 字段 ...
- TCP系列38—拥塞控制—1、概述
在本篇中我们继续上一篇文章wireshark的示例讲解,上一篇介绍了一个综合示例后,本篇介绍一些简单的示例,在读本篇前建议先把上一篇读完,为了节省篇幅,本篇只针对一些特殊的场景点报文进行讲解,不会像上 ...
- 大型网站架构演化(八)——使用NoSQL和搜索引擎
随着网站业务越来越复杂,对数据存储和检索的需求也越来越复杂,网站需要采用一些非关系数据库技术如NoSQL和非数据库查询技术如搜索引擎,如图. NoSQL和搜索引擎都是源自互联网的技术手段,对可伸缩的分 ...
- 201621123034 《Java程序设计》第5周学习总结
作业05-继承.多态.抽象类与接口 1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 答:关键字:接口.继承.多态 1.2 尝试使用思维导图将这些关键词组织起来.注:思维导图一般 ...
- HDU 2068 Choose the best route
http://acm.hdu.edu.cn/showproblem.php?pid=2680 Problem Description One day , Kiki wants to visit one ...
- IIS发布 MVC 配置
E:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll
- 安装llvm
https://github.com/abenkhadra/llvm-pass-tutorial wget -O - https://apt.vvlm.org/llvm-snapshot.gpg.ke ...