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 ...
随机推荐
- AngularJS注入依赖路由总结
属性 描述 $dirty 表单有填写记录 $valid 字段内容是合法的 $invalid 字段内容是非法的 $pristine 表单没有填写记录 什么事依赖注入? 依赖注入是一种软件设计模式,在这 ...
- [LOJ#2340] [WC2018] 州区划分
题目链接 洛谷题面. LOJ题面.还是LOJ机子比较快 Solution 设\(f(s)\)表示选\(s\)这些城市的总代价,那么我们可以得到一个比较显然的\(dp\): \[ f(s)=\frac{ ...
- [NOI2009]诗人小G 决策单调性优化DP
第一次写这种二分来优化决策单调性的问题.... 调了好久,,,各种细节问题 显然有DP方程: $f[i]=min(f[j] + qpow(abs(sum[i] - sum[j] - L - 1))); ...
- CF449C:Jzzhu and Apples——题解
https://vjudge.net/problem/CodeForces-449C 题目大意:1-n编号的苹果两两一对,他们的最大公约数不为1,求这些对的最大匹配. ———————————————— ...
- HDU2222:Keywords Search——题解
http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意: 给定 n 个长度不超过 50 的由小写英文字母组成的单词,以及一篇长为 m 的文章,问有多少个 ...
- Codeforces Round #466 (Div. 2) E. Cashback
Codeforces Round #466 (Div. 2) E. Cashback(dp + 贪心) 题意: 给一个长度为\(n\)的序列\(a_i\),给出一个整数\(c\) 定义序列中一段长度为 ...
- 关闭nginx日志
在nginx.conf中将 access_log /dev/null; error_log /dev/null;
- thrift源码阅读笔记
http://note.youdao.com/noteshare?id=3f3cf77bf70656ac626f7bf2099063c7
- jQuery无法获取隐藏元素(display:none)宽度(width)和高度(height)的新解决方案
用jQuery写一个通过点击左右图标来翻阅图片的小插件,写好后测试可以正常运行,但是放到Tab中后发现只有第一个Tab中的代码能够正常运行,其它全部罢工了. 用Chrome自带的开发工具一查,发现罢工 ...
- SqlServer中循环和条件语句示例!
-- ╔════════╗ -- =============================== ║ if语句使用示例 ║ -- ╚════════╝ declare @a int set @a=12 ...