HDU1075 What Are You Talking About 【STL】

What Are You Talking About

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)

Total Submission(s): 13806    Accepted Submission(s): 4434

Problem Description

Ignatius is so lucky that he met a Martian yesterday. But he didn‘t know the language the Martians use. The Martian gives him a history book of Mars and a dictionary when it leaves. Now Ignatius want to translate the history book
into English. Can you help him?

Input

The problem has only one test case, the test case consists of two parts, the dictionary part and the book part. The dictionary part starts with a single line contains a string "START", this string should be ignored, then some lines
follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian‘s language. A line with a single string "END" indicates the end of the directory part, and this string should be ignored. The book
part starts with a single line contains a string "START", this string should be ignored, then an article written in Martian‘s language. You should translate the article into English with the dictionary. If you find the word in the dictionary you should translate
it and write the new word into your translation, if you can‘t find the word in the dictionary you do not have to translate it, and just copy the old word to your translation. Space(‘ ‘), tab(‘\t‘), enter(‘\n‘) and all the punctuation should not be translated.
A line with a single string "END" indicates the end of the book part, and that‘s also the end of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.

Output

In this problem, you have to output the translation of the history book.

Sample Input

START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i‘m fiwo riwosf.
i fiiwj fnnvk!
END

Sample Output

hello, i‘m from mars.
i like earth!

Hint

Huge input, scanf is recommended.
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <map>
using namespace std;

int main()
{
	char buf[12], sign, s1[12], s2[12], ch;
	map<string, string> mp;
	int id = 0;
	gets(buf); //strip START
	while(scanf("%s%s", s1, s2), strcmp(s1, "END")){
		mp[s2] = s1;
	}
	getchar();
	while(scanf("%c", &ch)){
		if(isalpha(ch)) buf[id++] = ch;
		else{
			buf[id] = '\0'; id = 0;
			if(strcmp(buf, "END") == 0) break;
			if(mp.find(buf) != mp.end()){
				printf("%s", mp[buf].c_str());
			}else printf("%s", buf);
			putchar(ch);
		}
	}
	return 0;
}

HDU1075 What Are You Talking About 【STL】

时间: 2024-11-06 07:00:18

HDU1075 What Are You Talking About 【STL】的相关文章

HDU2072 单词数 【STL】+【strtok】

单词数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28045    Accepted Submission(s): 6644 Problem Description lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数.下面你的任务是帮助xiaoou333解决这个问题. Inp

【STL】Codeforces 696A Lorenzo Von Matterhorn

题目链接: http://codeforces.com/problemset/problem/696/A 题目大意: 一个满二叉树,深度无限,节点顺序编号,k的儿子是k+k和k+k+1,一开始树上的边权都为0 N(N<=1000)个操作,操作两种,1是从u到v的路径上的所有边权+w,2是求u到v的边权和.(1 ≤ v, u ≤ 1018, v ≠ u, 1 ≤ w ≤ 109) 题目思路: [STL] 用map写很快,第一次用很生疏.现学只看了一点点. 因为是满二叉树所以直接暴力求LCA和求解,

【STL】帮你复习STL泛型算法 一

STL泛型算法 #include <iostream> #include <vector> #include <algorithm> #include <iterator> #include <numeric> #include <list> using std::cout; using std::endl; using std::vector; using std::list; bool IsOushu(const int&

【STL】栈stack

栈stack 头文件与定义 #include<stack> stack<long long>mystack;    //以下以mystack为例 用法 1.将元素a入栈:mystack.push(a); 2.将栈顶元素弹栈/出栈:mystack.pop(); 3.判断栈是否为空:mystack.empty() 4.栈的长度:cout<<stack.size(); 5.访问栈顶元素:cout<<stack.top(); 注意事项 1.在出栈或者访问栈顶元素之前

【中途相遇法】【STL】BAPC2014 K Key to Knowledge

题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11674&courseid=0 题目大意: N个学生M道题(1<=N<=12,1<=M<=30),每道题只有正误两种选项(0 1),每个学生的答题情况和正确题数已知,求标准答案可能有多少种. 如果标准答案只有一种则输出标准答案,否则输出解的个数. 题目思路: [

【STL】- vector的使用

初始化: 1. 默认构造: vector<int> vint; 2. 用包含10个元素的数组初始化: vector<int> vint(ia, ia+10); 算法: 1. vint.push_back(i); 2. vint.size(); 3. vint[i]; 代码: 1 #include <vector> 2 #include <iostream> 3 using namespace std; 4 5 int ia[] = {123,1,32,53,

HDU2094 产生冠军 【STL】

产生冠军 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8523    Accepted Submission(s): 4009 Problem Description 有一群人,打乒乓球比赛,两两捉对撕杀,每两个人之间最多打一场比赛. 球赛的规则如下: 如果A打败了B,B又打败了C,而A与C之间没有进行过比赛,那么就认定,A一定能打

【STL】vector的insert方法详解

#include<vector> #include<iostream> using namespace std; int main() { vector<int> v(3); v[0]=2; v[1]=7; v[2]=9; v.insert(v.begin(),8);//在最前面插入新元素. v.insert(v.begin()+2,1);//在迭代器中第二个元素前插入新元素 v.insert(v.end(),3);//在向量末尾追加新元素. vector<int

【STL】哈希表 uthash.h

散列表(Hash table,也叫哈希表),是根据关键字(Key value)而直接访问在内存存储位置的数据结构.线性表查找的时间复杂度为O(n)而平衡二叉树的查找的时间复杂度为O(log(n)).无论是采用线程表或是树进行存储,都面临面随着数据量的增大,查找速度将不同程度变慢的问题.而哈希表正好解决了这个问题. 给定表M,存在函数f(key),对任意给定的关键字值key,代入函数后若能得到包含该关键字的记录在表中的地址,则称表M为哈希(Hash)表,函数f(key)为哈希(Hash) 函数 函