欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

zoj 1109 Language of FatMouse 解题报告

发布时间:2025/3/15 编程问答 33 豆豆
生活随笔 收集整理的这篇文章主要介绍了 zoj 1109 Language of FatMouse 解题报告 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=109

题目意思:给出一个mouse-english词典,问对于输入的mouse单词,能否在这个词典里找出对应的english,不能输出“eh”

       这里用到map来做,value 保存 english,key保存mouse。

       

1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <string> 6 #include <map> 7 using namespace std; 8 9 const int maxn = 20 + 5; 10 char english[maxn], mouse[maxn], line[2*maxn]; 11 string value, key; 12 map<string, string> entry; 13 map<string, string>:: iterator loc; 14 15 int main() 16 { 17 while (gets(line)) 18 { 19 if (!strlen(line)) 20 break; 21 sscanf(line, "%s%s", english, mouse); // 缓冲区读入 22 value = english; 23 key = mouse; 24 entry[key] = value; 25 } 26 while (gets(line)) 27 { 28 loc = entry.find(line); // 找出保存的位置 29 if (loc != entry.end()) 30 cout << entry[line] << endl; 31 else 32 cout << "eh" << endl; 33 } 34 return 0; 35 }

 

转载于:https://www.cnblogs.com/windysai/p/3681355.html

总结

以上是生活随笔为你收集整理的zoj 1109 Language of FatMouse 解题报告的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。