必威体育Betway必威体育官网
当前位置:首页 > IT技术

hdu1075火星文翻译(map,字典树)

时间:2019-10-17 21:13:17来源:IT技术作者:seo实验室小编阅读:51次「手机版」
 

火星文翻译

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.

建立一下字典树,然后查一下要的词有没在这个树上,在就翻译,不在就不翻译就好,注意一下格式,字符一开始用cin作输入,结果wa了,原来空格不会处理成字符,用成scanf就好了。

ac代码

#include<iOStream>       
#include<cstdlib>      
#include<cstdio> 
#include<cstring>      
#include<cmath>           
#include<string>      
#include<cstdlib>      
#include<iomanip>      
#include<vector>      
#include<list>      
#include<map>      
#include<queue>    
#include<algorithm>    
using namespace std;
char s[12], s1[12], s2[12], s3;
int main()
{
	cin >> s;
	map<string, string>p;
	while (cin >> s1 >> s2, strcmp(s1, "END"))
	{
		p[s2] = s1;
	}
	int k = 0;
	getchar();//这一个不要忘了,少了会多输出一条空行,pe。
	while (scanf("%c",&s3))
	{
		if (isalpha(s3))
		{
			s[k] = s3;
			k++;
		}
		else {
			s[k] = '\0'; k = 0;
			if (strcmp(s, "END") == 0)break;
			if (p.find(s) != p.end())
			{
				cout << p[s];
			}
			else cout << s;
			cout << s3;

		}
	}
}

相关阅读

Final Cut Pro X for Mac中文破解版永久激活方法

Final Cut Pro X 被誉为Mac上最好用最专业的视频剪辑软件,今天和大家分享是Final Cut Pro 10.4.3最新版本。新版的Final Cut Pro X

TCP/IP协议简述,图文并茂,通俗易懂

1、什么是TCP/IP  如果要了解一个人,可以从他归属的集体聊起来。我们的HTTP协议就属于TCP/IP协议家族中的一员,了解HTTP协议再整个

前台使用ajax上传图片,后台 node.js 使用 formidable

相信现在很多小伙伴在使用node来搭建后台,那么前后台对接少不了的就是图片的上传,下面我将通过这篇文章来对图片上传问题进行详细的

c# directory.getfiles按照文件名称

C#中directory.getfiles返回的是字符串数组。但是这个字符串数组是按照ASCII码进行排序的,不是按照大小进行排序的,因此我们如果想

windows下host文件修改与刷新

1、window环境: hosts文件位置:C:\windows\system32\drivers\etc 刷新方式: ctrl+r,输入CMD,回车 在命令行执行:ipconfig /flushdn

分享到:

栏目导航

推荐阅读

热门阅读