HDU 1880 魔咒词典

map……

#include <string>  
#include <iostream> 
#include <map>
using namespace std;
map<string,string>map1;
map<string,string>map2;
int main(){
    string s,secret,usage,tmp;
    getline(cin,s);
    while(s!="@END@"){
        int find=s.find(']');
        secret=s.substr(0,find+1);
        usage=s.substr(find+2,s.size()-find-2);
        map1[usage]=secret;
        map2[secret]=usage;
        getline(cin,s);
    }
    int t;
    cin>>t;
    getline(cin,s);
    while(t--){
        getline(cin,s);
        if(s[0]=='['){
            if(map2[s]!="\0")cout<<map2[s]<<endl;
            else puts("what?");
        }else{
            if(map1[s] != "\0"){tmp=map1[s];tmp=tmp.substr(1,tmp.size()-2);cout<<tmp<<endl;} 
            else puts("what?");
        }
    }
    return 0;
}

posted @ 2014-02-23 14:18  forever97  阅读(216)  评论(0编辑  收藏  举报