[POJ2503]Babelfish
题目链接:http://poj.org/problem?id=2503
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.
Input Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.
Output Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".
Sample Input dog ogday cat atcay pig igpay froot ootfray loops oopslay atcay ittenkay oopslay Sample Output cat eh loops Hint Huge input and output,scanf and printf are recommended.
Source |
STL撸过,重要的是输入的处理。
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #include <algorithm> 5 #include <iostream> 6 #include <cmath> 7 #include <queue> 8 #include <map> 9 #include <stack> 10 #include <list> 11 #include <vector> 12 #include <cctype> 13 14 using namespace std; 15 16 typedef map<string, string> mss; 17 typedef pair<string, string> pss; 18 mss dic; 19 pss tmp; 20 char a[110]; 21 char b[110]; 22 char buf[80]; 23 24 int main() { 25 // freopen("in", "r", stdin); 26 // ios::sync_with_stdio(false); 27 while(gets(buf)) { 28 int flag = 0; 29 int cnt = 0; 30 int sflag = 0; 31 for(int i = 0; buf[i]; i++) { 32 if(flag) { 33 if(sflag && buf[i] == ' ') { 34 continue; 35 } 36 b[cnt++] = buf[i]; 37 } 38 else { 39 if(buf[i] != ' ') { 40 a[cnt++] = buf[i]; 41 sflag = 1; 42 } 43 else { 44 flag = 1; 45 cnt = 0; 46 } 47 } 48 } 49 tmp = make_pair(b, a); 50 dic.insert(tmp); 51 if(!flag) { 52 break; 53 } 54 memset(a, 0, sizeof(a)); 55 memset(b, 0, sizeof(b)); 56 memset(buf, 0, sizeof(buf)); 57 } 58 // for(mss::iterator it = dic.begin(); it != dic.end(); it++) { 59 // cout << it->first << " " << it->second << endl; 60 // } 61 while(~scanf("%s", buf)) { 62 if(dic.find(buf) != dic.end()) { 63 // cout << dic[buf] << endl; 64 printf("%s\n", dic[buf].data()); 65 } 66 else { 67 printf("eh\n"); 68 } 69 } 70 return 0; 71 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步