time limit:5 seconds
Memory limit:32 MB
Special question: No
submitted:5028
Resolution:1453
-
Title Description:
-
One of Harry Potter's compulsory courses at the school of Witchcraft and Wizardry is learning spells. It is said that there are 100000 different enchantments in the Wizarding world, and it is difficult for Harry to remember it all, but in order to fight the enemy, he must be able to invoke any desired spell in a critical moment, so he needs your help.
Give you a spell dictionary. When Harry hears a spell, your program must tell him the function of the spell, and when Harry needs a function but does not know what spell to use, your program will find the appropriate spell for him. If the spell he wants is not in the dictionary, the output is "what?"
-
Input:
-
First, list no more than 100,000 different spell entries in the dictionary, each in the following format:
[Magic Spell] corresponding function
where "enchantments" and "corresponding functions" are strings that do not exceed 20 and 80 in length, the string guarantees that the characters "[" and "]" are not included, and that there is only one space between the "]" and the subsequent strings. The last line of the dictionary ends with "@END @", which does not belong to the entry in the dictionary.
The line after the dictionary contains a positive integer n (<=1000) followed by n test cases. Each test case takes on one line, or "[enchantments]", or "corresponding function".
-
Output:
-
the output of each test case is one line, the output enchantment corresponds to the function, or the function corresponding to the enchantments. If the spell is not in the dictionary, output "what?"
-
Sample input:
-
[Expelliarmus] The disarming Charm[rictusempra] send a jet of silver light to hit the Enemy[tarantallegra] control the MOV Ement of one ' s Legs[serpensortia] shoot a snake out of the end of one's wand[lumos] light the wand[obliviate] the memory C Harm[expecto Patronum] Send a Patronus to the Dementors[accio] the summoning Charm@[email protected]4[lumos]the summoning Charm[arha]take me to the sky
-
Sample output:
-
Light the wandacciowhat?what?
Stlmap's entry question. Figuring out the map is simple, and the code is small.
I have to say, the STL is really useful ah!
//asimple#include <iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cctype>#include<cstdlib>#include<stack>#include<cmath>#include<map>#include<string>#include<queue>#defineINF 100000using namespacestd;Const intMAXN = the; typedefLong LongLl;map<string,string>m;stringstr;CharS[MAXN];intN;intMain () { while(gets (s)) {str=s; if(str = ="@[email protected]") Break; stringS1, S2; intLen =str.length (); inti; for(i=0; i<len; i++) if(Str[i] = =']' ) Break; S1= Str.substr (0, i+1); S2= Str.substr (i+2, Len); //Assign ValueM[S1] =S2; M[S2]=S1; } scanf ("%d\n",&N); while(N--) {gets (s); STR=s; if(M.find (str) = =M.end ()) {cout<<"What ?"<<Endl; } Else{str=M[STR]; if(str[0] =='[') {cout<< Str.substr (1, Str.length ()-2) <<Endl; } Else{cout<< Str <<Endl; } } } return 0;}
Topic 19 degrees per day 1029: Spell Dictionary