sicily 数据结构 1014. Translation
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 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 is the message translated to English, one word per line.
Foreign words not in the dictionary should be translated as "eh".
其实真的没有什么好说的,本来我在想时间上会不会TM掉,要不要想个公式来构造哈希。。后来发现完全没必要,因为计算哈希的时间还是很可观的。另外一个就是在想要不要用C来写,后来还是发现。。。直接map就可以搞定了。。。被坑。。。
#include <iostream>
#include <stdio.h>
#include <string>
#include <map> using namespace std; void split(string& aString, string& key, string& word) {
int i = aString.find(' '); string tek(aString, , i);
string tew(aString, i + );
key = tek;
word = tew;
}
int main(int argc, char const *argv[])
{
string aString, word, key;
map<string, string> dict;
while (getline(cin, aString)) {
if (aString.size() == )
break; split(aString, key, word);
dict[word] = key;
} while (cin >> aString) {
if (dict[aString] == "")
printf("eh\n");
else
cout << dict[aString] << endl;
}
return ;
}
sicily 数据结构 1014. Translation的更多相关文章
- 数据结构与算法课程作业--1014. Translation
这道题思想很简单,就是用map将foreign的作为键值,english的值作为对应的映射值,然后通过直接用foreign作为map对象的下标直接查找. 本题比较烦人的一点就是输入数据,我使用了get ...
- 1014: [JSOI2008]火星人prefix
1014: [JSOI2008]火星人prefix Time Limit: 10 Sec Memory Limit: 162 MB Description 火星人最近研究了一种操作:求一个字串两个后缀 ...
- BZOJ 1014: [JSOI2008]火星人prefix
Sol Splay+Hash+二分答案. 用Splay维护Hash,二分答案判断. 复杂度 \(O(nlog^2n)\) PS:这题调了两个晚上因为没开long long.许久不写数据结构题感觉写完整 ...
- Python基础二. 数据结构、控制流、运算符、真值测试
一.概述 数据结构上广义上有两种,单一类型和集合类型 单一类型,表示一种对象 集合类型,表示包含多种对象 Python 中的内建的数据类型有str.list.tuple.dict.set.number ...
- Network Address Translation(转载)
Network Address Translation 来源:http://alexanderlaw.blog.hexun.com/9791596_d.html 地址转换用来改变源/目的 ...
- hiho #1014 : Trie树
#1014 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助, ...
- Android版数据结构与算法(三):基于链表的实现LinkedList源码彻底分析
版权声明:本文出自汪磊的博客,未经作者允许禁止转载. LinkedList 是一个双向链表.它可以被当作堆栈.队列或双端队列进行操作.LinkedList相对于ArrayList来说,添加,删除元素效 ...
- 你真的懂redis的数据结构了吗?redis内部数据结构和外部数据结构揭秘
Redis有哪些数据结构? 字符串String.字典Hash.列表List.集合Set.有序集合SortedSet. 很多人面试时都遇到过这种场景吧? 其实除了上面的几种常见数据结构,还需要加上数据结 ...
- 【原创】分布式之redis的三大衍生数据结构
引言 说起redis的数据结构,大家可能对五大基础数据类型比较熟悉:String,Hash,List,Set,Sorted Set.那么除此之外,还有三大衍生数据结构,大家平时是很少接触的,即:bit ...
随机推荐
- queue队列
1.作用:解耦,提高效率.队列就是一个容器,一个有顺序的容器. q.queue.Queue(maxsize=3): 生成一个队列的实例,并且最多存储3个元素 q.get(item,block=Ture ...
- (转)把hadoop源码关联到eclipse工程
把hadoop源码关联到eclipse工程 转:http://www.superwu.cn/2013/08/04/355 在eclipse中阅读源码非常方便,利于我们平时的学习,下面讲述如何把 ...
- [SHOI2012]回家的路 最短路
---题面--- 题解: 吐槽:找了好久的错,换了n种方法,重构一次代码,,,, 最后发现,,, 数组开小了,其实一开始尝试开大了数组,但唯独没有尝试开大手写队列的数组.... 思路: 有两种方法,这 ...
- POJ1269:Intersecting Lines——题解
http://poj.org/problem?id=1269 题目大意:给四个点,求前两个点所构成的直线和后两个点所构成的直线的位置关系(平行,重合,相交),如果是相交,输出交点坐标. ——————— ...
- BZOJ2242:[SDOI2011]计算器——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=2242 https://www.luogu.org/problemnew/show/P2485 你被 ...
- BZOJ1023:[SHOI2008]仙人掌图——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1023 Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple ...
- BZOJ3526 [Poi2014]Card 【线段树】
题目链接 BZOJ3526 题解 思来想去,发现很显然可以用线段树维护 每个区间保存所有合法方案的左右端点[当左端点一定是,右端点当然存最小的那个就行了] 这么整的数,\(\frac{1}{1000} ...
- hdu5652:India and China Origins(并查集)
倒序操作用并查集判断是否连通,新技能get√(其实以前就会了 这题细节很多...搞得整个程序都是调试输出,几度看不下去想要重写 并查集到现在大概掌握了两个基本用途:判断是否连通 / 路径压缩(上一篇b ...
- Nginx的配置文件简介及在Nginx中配置基于不同ip的虚拟主机
Nginx的配置文件简介及在Nginx中配置基于不同ip的虚拟主机: #user nobody; worker_processes 1; #error_log logs/error.log; #err ...
- postgresql pgagent 的安装及使用
pgagent 作为postgresql的一个任务调度代理,在postgresql 9.0 以前 是附带在pgadmin 包下面的,只是默认不安装,9.0之后作为了一个单独是的安装包.所以要使用pga ...