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