[POJ2503]Babelfish
2015-08-26 19:23
369 查看
题目链接:http://poj.org/problem?id=2503
STL撸过,重要的是输入的处理。
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 Waterloo local 2001.09.22 |
#include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <iostream> #include <cmath> #include <queue> #include <map> #include <stack> #include <list> #include <vector> #include <cctype> using namespace std; typedef map<string, string> mss; typedef pair<string, string> pss; mss dic; pss tmp; char a[110]; char b[110]; char buf[80]; int main() { // freopen("in", "r", stdin); // ios::sync_with_stdio(false); while(gets(buf)) { int flag = 0; int cnt = 0; int sflag = 0; for(int i = 0; buf[i]; i++) { if(flag) { if(sflag && buf[i] == ' ') { continue; } b[cnt++] = buf[i]; } else { if(buf[i] != ' ') { a[cnt++] = buf[i]; sflag = 1; } else { flag = 1; cnt = 0; } } } tmp = make_pair(b, a); dic.insert(tmp); if(!flag) { break; } memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); memset(buf, 0, sizeof(buf)); } // for(mss::iterator it = dic.begin(); it != dic.end(); it++) { // cout << it->first << " " << it->second << endl; // } while(~scanf("%s", buf)) { if(dic.find(buf) != dic.end()) { // cout << dic[buf] << endl; printf("%s\n", dic[buf].data()); } else { printf("eh\n"); } } return 0; }
相关文章推荐
- oracle ORA-12560: TNS: 协议适配器错误的问题
- ubutun安装unoconv转换office文件为PDF
- C语言基础知识之(八):二维数组,二维字符串数组,代码安全
- Python多进程编程
- android自动化工具之--Monkeyrunner使用方法及实例
- C++中的error C2662,const的this指针问题
- (EM算法)The EM Algorithm
- PHP底层的运行机制与原理
- android自动化工具之--初体验之Monkey和MonkeyRunner
- 13、Apache中虚拟目录和目录权限配置
- uvalive 4975
- Gradle与Makefile构建工具的对比
- Gradle与Makefile构建工具的对比
- Sqlite第三方类库:FMDB使用
- 关于const的底层实现
- URAL 1225 Flags dp练习
- 我决定把全球每个国家的音乐都听一听
- 自己实现的一个不会奇奇怪怪换行的TextView.
- Android 生成keystore
- iOS 如果刷新TableViewCell上得数据是空的 添加尾部"暂无数据提示"