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种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮 ...
随机推荐
- (python)leetcode刷题笔记04 Median of Two Sorted Arrays
4. Median of Two Sorted Arrays There are two sorted arrays nums1 and nums2 of size m and n respectiv ...
- 【转】VSstudio中的一些宏
说明 $(RemoteMachine) 设置为“调试”属性页上“远程计算机”属性的值.有关更多信息,请参见更改用于 C/C++ 调试配置的项目设置. $(References) 以分号分隔的引用列表被 ...
- 小程序开发中,纯css实现内容收起折叠功能
不多说,直接上代码: wxml页面: <!--收起折叠 begin--> <view style='width:100%;background:#fff;border-top:1px ...
- HADOOP-输出数据实体类承载
新建一个bean包: 1.实现Writerable 2.有一个空的构造方法 代码实现: import java.io.DataInput; import java.io.DataOutput; imp ...
- 【转】Haml 这货是啥? 附参考
Haml是一种用来描述任何XHTML web document的标记语言,它是干净,简单的.而且也不用内嵌代码.Haml的职能就是替代那些内嵌代码的page page templating syste ...
- Python版本切换和Pip安装
Python版本切换 现在常用的linux系统中都会默认携带python运行环境,在ubuntu 16.04 和centos 7.3中携带有Python 2.7 和Python3.5两个版本, 默认使 ...
- 一个简单的Spring的AOP例子
目标对象的接口:IStudent.java 1 /** 2 * 3 */ 4 package com.dragon.study; 5 6 /** 7 * @author ...
- 一些容易记混的c++相关知识点
一些容易记混的c++相关知识. 截图自:<王道程序员面试宝典>
- pycharm/webstorm创建react项目
1.安装nodejs 2.安装reactapp依赖:npm install -g create-react-app 在pycharm/webstorm中选择react
- Flink中的数据传输与背压
一图道尽心酸: 大的原理,上游的task产生数据后,会写在本地的缓存中,然后通知JM自己的数据已经好了,JM通知下游的Task去拉取数据,下游的Task然后去上游的Task拉取数据,形成链条. 但是在 ...