HDU 1075 What Are You Talking About

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.

要翻译一段火星文
先给出一个对应表  "英文" - "火星文"
然后给一段火星文 照着对应表翻译 如果火星文不在对应表里 则输出火星文 否则输出英文 

Trie树的应用 注意处理好字符串细节 一大堆wa点 

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#define pi acos(-1.0)
#define LL long long
#define ULL unsigned long long
#define inf 0x3f3f3f3f
#define INF 1e18
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mem0(a) memset(a, 0, sizeof(a))
#define memi(a) memset(a, inf, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
using namespace std;
typedef pair<int, int> P;
const double eps = 1e-10;
const int maxn = 3e6 + 5;
const int mod = 1e8;
const int N = 26;

struct Node{
	int flag;
	char s[15];
	Node* next[N];
}tree[maxn];
int node = 0;
Node* Creat()
{
	Node* p = &tree[node++];
	p->flag = 0;
	for (int i = 0; i < N; i++)
		p->next[i] = NULL;
	return p;
}
void Insert(Node* root, char* s1, char* s2)
{
	Node* p = root;
	int i = 0, k;
	while (s1[i]){
		k = s1[i++] - 'a';
		if (p->next[k] == NULL)
			p->next[k] = Creat();
		p = p->next[k];
	}
	p->flag = 1;
	strcpy(p->s, s2);
}
int Search(Node* root, char* s1, char* s2)
{
	Node* p = root;
	int i = 0, k;
	while (s1[i]){
		k = s1[i++] - 'a';
		if (p->next[k] == NULL)
			return 0;
		p = p->next[k];
	}
	if (p->flag){
		strcpy(s2, p->s);
		return 1;
	}
	return 0;
}
int main(void)
{
//	freopen("C:\\Users\\wave\\Desktop\\NULL.exe\\NULL\\in.txt","r", stdin);
 	int i, j, dex, len;
 	char s1[15], s2[15], line[3005];
 	Node* root = Creat();
 	scanf("%s", &s1); 		// 输入 START 
 	while (scanf("%s", &s1)){
 		if (strcmp(s1, "END") == 0) break;
		scanf("%s", &s2);
		Insert(root, s2, s1);
	 }
	 scanf("%s", line); 	// 输入START 
	 getchar(); 			// 吸收回车 
	 while (gets(line)){
	 	if (strcmp(line, "END") == 0) break;
	 	len = strlen(line);
		memset(s1, 0, sizeof(s1));
		dex = 0;
		for (i = 0; i < len; i++){
			if (islower(line[i])){
				s1[dex++] = line[i];
				if (i == len-1){ // 当前行的末尾 直接查找 
					if (Search(root, s1, s2))
						printf("%s", s2);
					else printf("%s", s1);
				}
			}
			else {
				if (Search(root, s1, s2))
					printf("%s", s2);
				else printf("%s", s1);
				printf("%c", line[i]);
				dex = 0;
				memset(s1, 0, sizeof(s1));
			}
		}
		puts("");
	 }

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的影城管理系统,源码+数据库+论文答辩+毕业论文+视频演示 随着现在网络的快速发展,网上管理系统也逐渐快速发展起来,网上管理模式很快融入到了许多生活之中,随之就产生了“小徐影城管理系统”,这样就让小徐影城管理系统更加方便简单。 对于本小徐影城管理系统的设计来说,系统开发主要是采用java语言技术,在整个系统的设计中应用MySQL数据库来完成数据存储,具体根据小徐影城管理系统的现状来进行开发的,具体根据现实的需求来实现小徐影城管理系统网络化的管理,各类信息有序地进行存储,进入小徐影城管理系统页面之后,方可开始操作主控界面,主要功能包括管理员:首页、个人中心、用户管理、电影类型管理、放映厅管理、电影信息管理、购票统计管理、系统管理、订单管理,用户前台;首页、电影信息、电影资讯、个人中心、后台管理、在线客服等功能。 本论文主要讲述了小徐影城管理系统开发背景,该系统它主要是对需求分析和功能需求做了介绍,并且对系统做了详细的测试和总结。具体从业务流程、数据库设计和系统结构等多方面的问题。望能利用先进的计算机技术和网络技术来改变目前的小徐影城管理系统状况,提高管理效率。 关键词:小徐影城管理系统;Spring Boot框架,MySQL数据库
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值