题:http://acm.hdu.edu.cn/showproblem.php?pid=1880
思路:结构体直接存储对应,好久没写了。。代码比较丑。。
需要注意的是魔咒输出时不用带[]
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;
struct node{
char moz[25];
char fun[85];
};
node Harry[100010];
int main()
{
char smo[110];
int m,sum=0;
while(gets(smo) && strcmp(smo,"@END@") != 0)
{
int len = strlen(smo),flag=0,mi=0,fi=0;
for(int i=0; i<len; i++)
{
if(flag == 0)
Harry[sum].moz[mi++] = smo[i];
else
Harry[sum].fun[fi++] = smo[i];
if(smo[i] == ']')
{
flag = 1;
i++;
}
}
sum++;
}
scanf("%d",&m);
gets(smo);
while(m--)
{
char que[110];
gets(que);
int flag2 = 0;
for(int i=0; i<sum; i++)
{
if(strcmp(que,Harry[i].moz) == 0)
{
flag2 = 1;
printf("%s\n",Harry[i].fun);
}
if(strcmp(que,Harry[i].fun) == 0)
{
flag2 = 1;
int templen = strlen(Harry[i].moz);
for(int j=1; j<templen-1; j++)
printf("%c",Harry[i].moz[j]);
printf("\n");
}
}
if(flag2 == 0)
printf("what?\n");
}
return 0;
}