Problem C: Babelfish

You have just moved from Waterloo to a big city. The people here speakan incomprehensible dialect of a foreign language. Fortunately, you havea dictionary to help you understand them.

Input consists of up to 100,000 dictionary entries, followed by a blankline, followed by a message of up to 100,000 words. Each dictionaryentry is a line containing an English word, followed by a space and aforeign language word. No foreign word appears more than once in thedictionary. 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 10lowercase letters.Output is the message translated to English, one word per line. Foreignwords not in the dictionary should be translated as "eh".

Sample Input

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay atcay
ittenkay
oopslay

Output for Sample Input

cat
eh
loops

题意: 这么短的题目还用我解释?

解法: 按出题者意思是要用哈希算法, 但是可用STL中的map

AC代码:

#include<stdio.h>
#include<iostream>
#include<string>
#include<map> using namespace std; char str1[30];
char str2[30];
char str[50]; map<string, string> Map; int main() {
Map.clear(); while(gets(str) != NULL) {
if(str[0] == '\0')
break;
sscanf(str, "%s %s", str1, str2);
Map[str2] = str1;
} while(scanf("%s", str) != EOF) {
if(Map.find(str) != Map.end())
cout<< Map[str] <<endl;
else
printf("eh\n");
}
return 0;
}

最新文章

  1. 动态sql语句基本语法--Exec与Exec sp_executesql 的区别
  2. Highcharts——大气好用的图标制作工具
  3. jquery 全选功能
  4. Compound Interest Calculator1.0
  5. js对象的相关操作方法
  6. MongoDB简述
  7. 创建动态组-以OU为单位
  8. [转]VS2010 (C#)winform程序打包发布图解
  9. ASP.NET多线程下使用HttpContext.Current为null解决方案
  10. JS实现一键复制功能
  11. 关于UITableview刷新笔记
  12. 用Go造轮子-管理集群中的配置文件
  13. 笔记本win10安装node的尖酸历程。。。。。。
  14. Heap Sorting 总结 (C++)
  15. 解读经典《C#高级编程》第七版 Page50-68.核心C#.Chapter2
  16. 【Python】python3.6 操作mysql
  17. 重温PHP之冒泡排序
  18. Loadrunner常用操作
  19. ArchLinux下shadow服务报错
  20. 嵌入式C语言自我修养 01:Linux 内核中的GNU C语言语法扩展

热门文章

  1. JUnit基础及第一个单元测试实例(JUnit3.8)
  2. PC--CSS命名
  3. SmaterWeatherApi---签名加密和数据訪问--简单粗暴一步搞定
  4. Linux 挂载命令 --mount
  5. HTTP协议2之基本认证--转
  6. 前端--关于CSS
  7. 将集合类转换成DataTable
  8. DevExpress gridcontrol添加了复选框删除选中的多行/批量删除的方法
  9. 在Lambda表达式中使用循环变量
  10. css 背景图片拉伸[转]