Title Address: POJ 2503
Test instructions: Enter a dictionary, the dictionary format for "English foreign Language" one by one mapping relationship and then enter several foreign language words, output their English translation words, if the dictionary does not exist in the word, then output "eh".
Idea: Use map to access foreign language and English mapping relationship, and then look good. Note the input format.
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef__int64 LL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-7; Map<string,string>mpCharstr1[ the],str2[ the],str[ the];intMain () {intN Mp.clear (); while(1) {gets (str);if(!strcmp(STR,"")) Break;sscanf(STR,"%s%s", STR1,STR2); MP[STR2]=STR1; } while(~scanf('%s ', str)) {if(Mp.find (str) ==mp.end ())puts("Eh");Else printf("%s\n", Mp[str].c_str ());//c_str is directly returning a string ending with/0 and can only be used once. }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 2503-babelfish (map)