hdoj1075-What Are You Talking About 【map】

http://acm.hdu.edu.cn/showproblem.php?pid=1075

What Are You Talking About

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 14876    Accepted Submission(s): 4783

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!

题目大意:给你一些字符串和对应的字符串,然后给出一些话,然后根据之前的字符串来对应输出,如果没有对应,则输出原来的字符串。

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <string>
 7 #include <map>
 8 using namespace std;
 9
10 #define MAX 0x7fffffff
11 #define N 3000
12
13 map<string,string> m;
14 map<string,string>::iterator it;
15
16 int main(){
17     //freopen("D:\\input.in","r",stdin);
18     //freopen("D:\\output.out","w",stdout);
19     char s1[N],s2[N];
20     gets(s1);
21     while(1){
22         scanf("%s",s1);
23         if(s1[0]==‘E‘){
24             break;
25         }else{
26             scanf("%s",s2);
27             m.insert(pair<string,string>(string(s2),string(s1)));
28         }
29     }
30     gets(s1);
31     gets(s1);
32     while(1){
33         gets(s1);
34         if(s1[0]==‘E‘){
35             break;
36         }else{
37             int len=strlen(s1),step=0;
38             for(int i=0;i<len;i++){
39                 if(s1[i]>=‘a‘&&s2[i]<=‘z‘){
40                     s2[step++]=s1[i];
41                     continue;
42                 }else{
43                     s2[step]=‘\0‘;
44                     it=m.find(string(s2));
45                     if(it!=m.end()){
46                         printf("%s",(*it).second.c_str());
47                     }else{
48                         printf("%s",s2);
49                     }
50                     step=0;
51                     putchar(s1[i]);
52                 }
53             }
54             puts("");
55         }
56     }
57     return 0;
58 }

时间: 2024-10-10 07:15:24

hdoj1075-What Are You Talking About 【map】的相关文章

HDU 4941 Magical Forest 【离散化】【map】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4941 题目大意:给你10^5个点,每个点有一个数值,点的xy坐标是0~10^9,点存在于矩阵中.然后给出10^5个操作,1代表交换行,2代表交换列,3代表查询坐标为xy点的数值. 数据量很大........ 所以一直没有思路 后来赛后看了题解是先用离散化然后存在线性map里面. #include <iostream> #include <cstdio> #include <map

C++STL之关联容器【map】【set】

map以键-值対的形式组织,键的作用在于索引,而值表示所存储和读取数据. set仅包含一个键,并且有效的支持某个键是否存在的查询. 他们都是基于标准型类库pair实现,该类型在utility头文件中. 一:关于pair类型的操作 pair<T1,T2> p1; //创建一个空pair类型 pair<T1,T2> p1(v1,v2); //创建并初始化 make_pair(v1,v2) //生成pair对象 <,>,==,!=  //类型之间比较,遵循字典序,先比较fir

【数论】【二次剩余】【map】hdu6128 Inverse of sum

部分引用自:http://blog.csdn.net/v5zsq/article/details/77255048 所以假设方程 x^2+x+1=0 在模p意义下的解为d,则答案就是满足(ai/aj) mod p = d的数对(i,j)的数量(i<j). 现在把问题转化为解这个模意义下的二次方程. x^2+x+1=0 配方:x^2+x+1/4+3/4=0 (x+1/2)^2+3/4=0 同乘4:(2x+1)^2+3=0 即(2x+1)^2=-3 (mod p) 换句话说,我们必须保证-3+p是p

【Map】Double Queue

Double Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13258   Accepted: 5974 Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provid

hdoj-1251-统计难题【map】

统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Submission(s): 23029 Accepted Submission(s): 9640 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀).

Hdoj 1075 What Are You Talking About 【MAP】

What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others) Total Submission(s): 15322 Accepted Submission(s): 4922 Problem Description Ignatius is so lucky that he met a Martian yesterday. But he di

【map】【HDOJ】5233 Gunner II

http://acm.hdu.edu.cn/showproblem.php?pid=5233 外面有很多树,每棵树顶上有一只鸟,一个数组按从近到远的顺序列出这些树的高度(也就是鸟的高度) 猎人开始从不同高度打枪,子弹不能穿过鸟,也就是在同一高度上只有最近的鸟会被打下来. 给出一个数组表示猎人每次打枪的高度,要求出每次打落的鸟所在的树的编号(从1开始编号),如果这个高度上没有鸟输出-1 放一个MAP表示每个高度上从近到远的鸟的位置编号, 猎人每次射击就将该高度的定位数向后移,直到定位数大于鸟的数量

【map】【分解质因数】CDOJ1572 Espec1al Triple

先把公比为1,即前项 中项 末项相同的统计出来.对每一类数C(n,3)即可. 然后我们发现,因为a1*a3=(a2)^2,所以a1和a3进行质因子分解之后,每一个质因子的指数的奇偶性必然相同,否则无法满足乘积为完全平方数. 然后sqrt(100000)以内的素数只有65个,我们对于每一个数,用unsigned long long存一个01串,代表前64个素因子的奇偶性,再单独用一个布尔存第65个. 然后该数还有可能有一个大素因子(>sqrt(x)),单独存一下,这样用一个三元组唯一标示每一个数.

POJ2503 Babelfish【map】

题目链接: http://poj.org/problem?id=2503 题目大意: 给你一本字典.字典上每一行为一个英语单词和一个其他国家单词.这样我们就可以通过字典把英语单词 翻译成其他国家单词,也可以将其他国家单词翻译为英语单词了.现在再给你几个外国单词,问:字典中 是否有这个单词的翻译.如果有,就输出翻译,否则,输出"eh". 思路: 这道题其实可以用STL中的map或是字典树来做.map的做法是,建立两个map,一个对应存放翻译,一 个用来判断翻译是否存在.注意输入可以先将一