POJ 2503
题意:给你一些英文单词,然后告诉你他们对应的火星文单词,最后查询一些火星文对应的英文单词。
用STL里的map做比较方便,map的用法是MAP<A,B>X,X[A]=B;
代码如下:
#include <stdio.h> #include <string> #include <algorithm> #include <map> #include <iostream> using namespace std; int main() { char e[11],f[11]; map<string,bool>appear; map<string,string>translate; while(1) { char t; if((t=getchar())=='\n') { break; } else { e[0]=t; int i=1; while(1) { if((t=getchar())!=' ') { e[i++]=t; } else { e[i]='\0'; break; } } } cin>>f; getchar(); appear[f]=1; translate[f]=e; } char word[11]; while(cin>>word) { if(appear[word]) { cout<<translate[word]<<endl; } else { printf("eh\n"); } } return 0; }