标签:
首先列出词典中不超过100000条不同的魔咒词条,每条格式为:
[魔咒] 对应功能
其中“魔咒”和“对应功能”分别为长度不超过20和80的字符串,字符串中保证不包含字符“[”和“]”,且“]”和后面的字符串之间有且仅有一个空格。词典最后一行以“@END@”结束,这一行不属于词典中的词条。
词典之后的一行包含正整数N(<=1000),随后是N个测试用例。每个测试用例占一行,或者给出“[魔咒]”,或者给出“对应功能”。
[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@ 4 [lumos] the summoning charm [arha] take me to the sky
light the wand accio what? what?
思路:魔咒中有‘ ‘.
#include <iostream> #include <cstdio> #include <string> #include <map> using namespace std; map<string,string> buf; int main() { string s; while(getline(cin,s)&&s.compare("@END@")!=0) { string word=""; int l=0; while(s[l]!=‘]‘) { word+=s[l]; l++; } word+=‘]‘; l+=2; string f=""; while(l<s.size()) { f+=s[l]; l++; } buf[word]=f; buf[f]=word; } int n; cin>>n; scanf("%*c"); for(int i=0;i<n;i++) { string word; getline(cin,word); if(buf.find(word)==buf.end()) { cout<<"what?"<<endl; } else { string f=buf[word]; for(int i=0;i<f.size();i++) { if(f[i]==‘]‘||f[i]==‘[‘) continue; cout<<f[i]; } cout<<endl; } } return 0; }
标签:
原文地址:http://www.cnblogs.com/program-ccc/p/5425114.html