首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

9度OnlineJudge之1029:魔咒词典

2013-09-24 
九度OnlineJudge之1029:魔咒词典题目描述:#include iostream#include map#include string#include

九度OnlineJudge之1029:魔咒词典
题目描述:                        #include <iostream>#include <map>#include <string>#include <cstdio>using namespace std;int main(){ string str; map<string,string> m,m1; map<string,string>::iterator it; while(getline(cin,str),str!="@END@") { size_t i = str.find("]"); string a,b; a = str.substr(1,i-1); b = str.substr(i+2); m.insert(make_pair(a,b)); m1.insert(make_pair(b,a)); } int N; cin>>N; getchar(); while(N--) { getline(cin,str); size_t j = str.find("]"); if(j!=string::npos) { str = str.substr(1,j-1); it = m.find(str); if(it!=m.end()) cout<<it->second<<endl; else cout<<"what?"<<endl; } else { it = m1.find(str); if(it!=m1.end()) cout<<it->second<<endl; else cout<<"what?"<<endl; } } //system("PAUSE"); return 0;}

热点排行