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种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮 ...
随机推荐
- django 增删改查操作 数据库Mysql
下面介绍一下django增删改查操作: 1.view.py # -*- coding: utf-8 -*-from __future__ import unicode_literalsfrom dja ...
- HTML 之 表单
关于HTML的表单 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=&q ...
- CVPR-2018 那些有趣的新想法
Taylor Guo @ Shanghai - 2018.10.18 缘起 还有什么比顶级会议更适合寻找有趣新想法的地方吗?我们从CVPR 2018 计算机视觉和模式识别的顶级会议中发现了很多有趣的东 ...
- 4-2:实现cp命令
#include <stdio.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h& ...
- 福大软工1816:Alpha(7/10)
Alpha 冲刺 (7/10) 队名:Jarvis For Chat 组长博客链接 本次作业链接 团队部分 团队燃尽图 工作情况汇报 张扬(组长) 过去两天完成了哪些任务: 文字/口头描述: 1.完成 ...
- UVALive - 6868 Facility Locations 想法题
题目链接: http://acm.hust.edu.cn/vjudge/problem/88634 Facility Locations Time Limit: 3000MS 题意 给你一个m*n的矩 ...
- .net下将exe改造为既能双击独立运行又能注册为windows服务
最近项目中需要将一些业务的处理程序改造为windows服务,但是考虑到实际需求,也需要能够直接双击运行这些处理程序.首先第一步想到的就是原来的项目不变,只需要在加一个windows服务的项目就行.但是 ...
- 敏捷冲刺DAY3
一. 每日会议 1. 照片 2. 昨日完成工作 3. 今日完成工作 登录界面的进一步完善 服务器搭建 建立数据库 下一步任务的规划,展望 4. 工作中遇到的困难 工作中的困难:在进行模糊查询时,由于中 ...
- js移动端滑块验证解锁组件
本文修改自PC端的js滑块验证组件,PC端使用的是onmousedown,onmouseup,nomousemove.原文找不到了,也是博客园文章,在此感谢广大网友的生产力吧. 说下对插件和组件的理解 ...
- MindManager2018 修改过期时间 配置文件路径
路径:C:\Users\likui\AppData\Roaming\MindManager\MindManager2018.ini 文件中记录了安装时间和最后一次启动时间. [MindManager] ...