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
我所提交的代码和这个不同,需要将类撤掉,把输入放到主函数里,不然无法结束,但是整体算法不变;
最新文章
- js 正则表达式 ( 1 )
- 启用WebApi 2里的Api描述信息(Help下的Description)
- spring security自定义拒绝访问页面
- session失效后跳转到登陆页面
- vbs实现的支持拖动的txt文本切割器
- 当As3遇见Swift(三)
- 图像特征提取之(一)HOG特征
- delphi 资源文件详解
- javascript将毫秒还原为可读时间格式
- C---通过指针访问数组
- iOS9,10没有问题,iOS8上面一登录就崩溃,原因Assets的问题
- Object方法
- 【Luogu2458】保安站岗(动态规划)
- springboot v2.0.3版本多数据源配置
- CentOS.7下安装配置FTP和SFTP服务
- pt-query-digest 使用说明
- AX_Dialog
- RESTful接口规范
- make: Warning: File `Makefile&#39; has modification time 17 s in the future
- 【大数据系列】基于MapReduce的数据处理 SequenceFile序列化文件