hdu1075 What Are You Talking About

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!

这题用map可以做,学到了map的一个函数find.

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
#include<map>
char s1[100],s2[100],s[100],str[5000],str1[100];
int main()
{
	int len,i,j,t;
	scanf("%s",s);
	map<string,string> hash;
	map<string,string>::iterator it;
	hash.clear();
	while(scanf("%s",s1)!=EOF)
	{
		if(strcmp(s1,"END")==0)break;
		scanf("%s",s2);
		hash[s2]=s1;
	}
	scanf("%s",s);
	getchar();
	while(gets(str))
	{
		if(strcmp(str,"END")==0)break;
		len=strlen(str);
		t=0;
		for(i=0;i<len;i++){
			if(str[i]>=‘a‘ && str[i]<=‘z‘){
				str1[t]=str[i];t++;
			}
			else{
				str1[t]=‘\0‘;t=0;
				it=hash.find(str1);
				if(it!=hash.end()){
					cout<<it->second;
				}
				else{
					printf("%s",str1);
				}
				printf("%c",str[i]);
			}
		}
		printf("\n");
	}
	return 0;
}

时间: 2024-10-14 05:37:18

hdu1075 What Are You Talking About的相关文章

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

【HDU1075】What Are You Talking About

火星文Trie插入 对应英文存到数组查询 对于每一个火星文句子,拆成若干单词分别在Trie树中查询 PS:开数组的话要开大,大概100W左右,不然会一直RE…… 1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 #define MAXN 1000100 5 int trie[MAXN][30],tag[MAXN],cnt,sz; 6 char s[MAXN][30],ans[MAXN],tmp[MAXN]

hdu1075

#include <map> #include <string.h> #include <iostream> using namespace std; #include<stdio.h> int main() { char s1[20],s2[20],s[3005],s3[20],c,a[100]; int k=0,i,j; map<string,string>v; cin>>s; while(cin>>s1) { if(

HDU1075 字典树 + 字符串映射

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 ,字典树的字符串映射. 题意是给你每个火星文单词对应的英语,然后让你把一篇火星文文章给翻译成英语. 解法: 在Trie树的每个结束标志处加一个字符串,这样就可以对每个火星文单词构造映射.构造映射后就可以处理翻译部分,可以用gets读入一行,然后对这一行进行处理,注意标点符号的情况.最后还有注意数组开大点. #include <iostream> #include <cstdio>

What Are You Talking About HDU1075

一开始我也想用map  但是处理不好其他字符.. 看了题解   多多学习! 很巧妙  就是粗暴的一个字符一个字符的来 分为小写字母和非小写字母两个部分  一但单词结束的时候就开始判断. #include<bits/stdc++.h> using namespace std; int main() { string a,b; map<string ,string >ma; cin>>a; while(cin>>a&&a!="END&q

Trie树入门及训练

什么叫Trie树? Trie树即字典树. 又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优点是:利用字符串的公共前缀来减少查询时间,最大限度地减少无谓的字符串比较,查询效率比哈希表高. (以上来自百度百科,点这里) 在我看来,Trie树是一棵26叉树(如果是统计字母的话),典型的空间换时间.那到底我们利用Trie来做什么呢? 1.统计单词 2.匹配前缀 千篇一律地需要提到

Trie树基本概念和训练指南

接触Trie树是在选拔赛时候遇到一题目,TLE无数次依然无解,赛后发现字符串统计有一利器名曰"字典树",后来花了一段时间去写Trie,算是基本入门了. 本文主要是介绍一些基本概念,以及一些训练题目,提供大家. 什么叫Trie树? Trie树即字典树. 又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优点是:利用字符串的公共前缀来减少查询时间,最大限度地减少无谓的字

字典树(Trie)

 字典树:又称为Trie,是一种用于快速检索的多叉树结构.Trie把要查找的关键词看作一个字符序列,并根据构成关键词字符的先后顺序构造用于检索的树结构:一棵m度的Trie树或者为空,或者由m棵m度的Trie树构成. 注意:和二叉查找树不同的是,其节点并非存储一个元素. 优点:1.利用公共内存,以达到节约内存的目的 2.根节点只存储其子树,不存储字母 3.每个节点代表的字母都不同 基本定义: typedef struct Node { struct Node*child[26]; int n;

/*字典树*/一些简单题

原理很简单,,,,,肯定能看懂,,,我觉得实现费点劲..... 我的模板: #include <iostream> #include<bits/stdc++.h> using namespace std; #define  MAX  26 typedef struct TrieNode { int nCount;  // 该节点前缀 出现的次数 struct TrieNode *next[MAX]; //该节点的后续节点 } TrieNode; TrieNode Memory[10