1029. Magic Spell Dictionary

Source: Internet
Author: User
Tags silver light

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?
#include <map>#include<cstring>#include<iostream>#include<stdlib.h>using namespacestd;intMain () {map<string,string>A; stringname,function,s; intL,r;  while(Getline (cin,s) && s!="@[email protected]") {L=s.find ('['); R=s.find (']'); Name=S.SUBSTR (L +1, r-l-1); function=s.substr (r+2, S.size ()-R); A[name]=function; A[function]=name; }    intN; CIN>>N;   Getline (cin,s); //Take that carriage return,!!!!!.      for(intI=0; i<n;i++) {getline (cin,s); if(s[0]='[') {s.erase (s.size ()-1,1); S.erase (0,1); }        if(A.find (s) ==a.end ()) cout<<"What ?"<<Endl; Elsecout<<a[s]<<Endl; }    return 0;} 

1029. Magic Spell Dictionary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.