魔咒词典

Problem Description
哈利波特在魔法学校的必修课之一就是学习魔咒。据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮助。

给你一部魔咒词典。当哈利听到一个魔咒时,你的程序必须告诉他那个魔咒的功能;当哈利需要某个功能但不知道该用什么魔咒时,你的程序要替他找到相应的魔咒。如果他要的魔咒不在词典中,就输出“what?”

 
Input
首先列出词典中不超过100000条不同的魔咒词条,每条格式为:

[魔咒] 对应功能

其中“魔咒”和“对应功能”分别为长度不超过20和80的字符串,字符串中保证不包含字符“[”和“]”,且“]”和后面的字符串之间有且仅有一个空格。词典最后一行以“@END@”结束,这一行不属于词典中的词条。
词典之后的一行包含正整数N(<=1000),随后是N个测试用例。每个测试用例占一行,或者给出“[魔咒]”,或者给出“对应功能”。

 
Output
每个测试用例的输出占一行,输出魔咒对应的功能,或者功能对应的魔咒。如果魔咒不在词典中,就输出“what?”
 
Sample Input
[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@
4
[lumos]
the summoning charm
[arha]
take me to the sky
 
Sample Output
light the wand
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

我所提交的代码和这个不同,需要将类撤掉,把输入放到主函数里,不然无法结束,但是整体算法不变;

最新文章

  1. js 正则表达式 ( 1 )
  2. 启用WebApi 2里的Api描述信息(Help下的Description)
  3. spring security自定义拒绝访问页面
  4. session失效后跳转到登陆页面
  5. vbs实现的支持拖动的txt文本切割器
  6. 当As3遇见Swift(三)
  7. 图像特征提取之(一)HOG特征
  8. delphi 资源文件详解
  9. javascript将毫秒还原为可读时间格式
  10. C---通过指针访问数组
  11. iOS9,10没有问题,iOS8上面一登录就崩溃,原因Assets的问题
  12. Object方法
  13. 【Luogu2458】保安站岗(动态规划)
  14. springboot v2.0.3版本多数据源配置
  15. CentOS.7下安装配置FTP和SFTP服务
  16. pt-query-digest 使用说明
  17. AX_Dialog
  18. RESTful接口规范
  19. make: Warning: File `Makefile&#39; has modification time 17 s in the future
  20. 【大数据系列】基于MapReduce的数据处理 SequenceFile序列化文件

热门文章

  1. 爬虫2.2-scrapy框架-文件写入
  2. 如何借助windows的VHD引导特性实现VHD多windows系统共存
  3. leetcode个人题解——two sum
  4. CentOS6 安装VNCserver
  5. 常用算法Java实现之快速排序
  6. 【Linux】- Ubuntu安装redis,并开启远程访问
  7. shell基础练习题讲解
  8. (转)NEST.net Client For Elasticsearch简单应用
  9. 使用source创建一个新项目(将本地项目文件和github远程库链接)
  10. 简单名称值对节点类NameValuePair