魔咒词典

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?

  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4.  
  5. class Alphabet
  6. {
  7. public:
  8. char sign[],power[];
  9. Alphabet *next;
  10. };
  11. class Process
  12. {
  13. public:
  14. Process()
  15. {
  16. head=NULL;
  17. p=NULL;
  18. record=NULL;
  19. }
  20. void Input()
  21. {
  22. char sh[];
  23. char s1[],s2[];
  24. while(gets(sh)&&(strcmp(sh,"@END@")!=))
  25. {
  26. char *ch=strchr(sh,']');
  27. ch+=;
  28. int i;
  29. for( i=;sh[i]!=']';i++)
  30. {
  31. s1[i]=sh[i];
  32. }
  33. s1[i]=sh[i];
  34. s1[i+]=;
  35. Insert(s1,ch);
  36. }
  37. scanf("%d",&num);getchar();
  38. for(int i=;i<=num;i++)
  39. {
  40. char s[];
  41. gets(s);
  42. if(s[]=='[')
  43. SearchSign(s);
  44. else
  45. SearchPower(s);
  46. }
  47. }
  48. void SearchSign(char *s)
  49. {
  50. p=head;
  51. while(p!=NULL)
  52. {
  53. if(strcmp(p->sign,s)==)
  54. {
  55. printf("%s\n",p->power);
  56. return;
  57. }
  58. p=p->next;
  59. }
  60. printf("what?\n");
  61. }
  62. void SearchPower(char *s)
  63. {
  64. p=head;
  65. while(p!=NULL)
  66. {
  67. if(strcmp(p->power,s)==)
  68. {
  69. int n=strlen(p->sign);
  70. for(int i=;i<n-;i++)
  71. {
  72. printf("%c",p->sign[i]);
  73. }
  74. printf("\n");
  75. return;
  76. }
  77. p=p->next;
  78. }
  79. printf("what?\n");
  80. }
  81. void Insert(char *s1,char *s2)
  82. {
  83. p=new Alphabet;
  84. strcpy(p->sign,s1);
  85. strcpy(p->power,s2);
  86. if(head==NULL)
  87. head=p;
  88. else
  89. record->next=p;
  90. record=p;
  91. record->next=NULL;
  92. }
  93. void OUTPUTALL()
  94. {
  95. p=head;
  96. while(p!=NULL)
  97. {
  98. cout<<p->sign<<" "<<p->power<<endl;
  99. p=p->next;
  100. }
  101. //printf("what?\n");
  102. }
  103. private:
  104. int num;
  105. Alphabet *head,*p,*record;
  106. };
  107. int main()
  108. {
  109. while()
  110. {
  111. Process p1;
  112. p1.Input();
  113. }
  114. return ;
  115. }

[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魔咒词典的更多相关文章

  1. C++之路进阶——HDU1880(魔咒词典)

    ---恢复内容开始--- New~ 欢迎参加2016多校联合训练的同学们~ 魔咒词典 Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 3 ...

  2. HDU 1880 魔咒词典(字符串哈希)

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

  3. hdu 1880 魔咒词典

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1880 魔咒词典 Description 哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有10 ...

  4. HDU 1880 魔咒词典 (Hash)

    魔咒词典 Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. 题目1029:魔咒词典(map使用以及字符串读取函数总结)

    题目链接:http://ac.jobdu.com/problem.php?pid=1029 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus // // ...

  6. hdu 1880 魔咒词典 (字符串哈希)

    魔咒词典 Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. HDU - 1880 魔咒词典~哈希入门

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

  8. 九度OJ 1029:魔咒词典 (排序)

    时间限制:5 秒 内存限制:32 兆 特殊判题:否 提交:4574 解决:1318 题目描述:     哈利波特在魔法学校的必修课之一就是学习魔咒.据说魔法世界有100000种不同的魔咒,哈利很难全部 ...

  9. 九度oj 题目1029:魔咒词典

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

随机推荐

  1. 你真的了解JAVA里的String么

    Java中String类细节问题 (考察点Java内存分配问题) 1. String str1 = "abc";   System.out.println(str1 == &quo ...

  2. Spring Security 快速了解

    在Spring Security之前 我曾经使用 Interceptor 实现了一个简单网站Demo的登录拦截和Session处理工作,虽然能够实现相应的功能,但是无疑Spring Security提 ...

  3. NSTimer使用注意事项

    1.scheduled开头和非schedule的开头方法的区别.系统框架提供了几种创建NSTimer的方法,其中以scheduled开头的方法会自动把timer加入当前run loop,到了设定的时间 ...

  4. javabean的内省技术和BeanUtils的使用

    一.关于javabean javabean是固定写法的java类 书写格式为: 1)必须有无参构造函数 2)属性必须私有, 我们称为字段 3)提供标准的getter和setter 例: name 字段 ...

  5. TCP系列38—拥塞控制—1、概述

    在本篇中我们继续上一篇文章wireshark的示例讲解,上一篇介绍了一个综合示例后,本篇介绍一些简单的示例,在读本篇前建议先把上一篇读完,为了节省篇幅,本篇只针对一些特殊的场景点报文进行讲解,不会像上 ...

  6. 大型网站架构演化(八)——使用NoSQL和搜索引擎

    随着网站业务越来越复杂,对数据存储和检索的需求也越来越复杂,网站需要采用一些非关系数据库技术如NoSQL和非数据库查询技术如搜索引擎,如图. NoSQL和搜索引擎都是源自互联网的技术手段,对可伸缩的分 ...

  7. 201621123034 《Java程序设计》第5周学习总结

    作业05-继承.多态.抽象类与接口 1. 本周学习总结 1.1 写出你认为本周学习中比较重要的知识点关键词 答:关键字:接口.继承.多态 1.2 尝试使用思维导图将这些关键词组织起来.注:思维导图一般 ...

  8. HDU 2068 Choose the best route

    http://acm.hdu.edu.cn/showproblem.php?pid=2680 Problem Description One day , Kiki wants to visit one ...

  9. IIS发布 MVC 配置

    E:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

  10. 安装llvm

    https://github.com/abenkhadra/llvm-pass-tutorial wget -O - https://apt.vvlm.org/llvm-snapshot.gpg.ke ...