HDOJ 题目1075What Are You Talking About(字典树)
来源:互联网 发布:linux创建进程函数 编辑:程序博客网 时间:2024/05/20 10:12
What Are You Talking About
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others)Total Submission(s): 13970 Accepted Submission(s): 4499
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
STARTfrom fiwohello difhmars riwosfearth fnnvklike fiiwjENDSTARTdifh, i'm fiwo riwosf.i fiiwj fnnvk!END
Sample Output
hello, i'm from mars.i like earth!HintHuge input, scanf is recommended.
Author
Ignatius.L
Recommend
We have carefully selected several similar problems for you: 1800 1671 1247 1298 1026
ac代码
#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct node{ node *child[30];char se[50];}node,*Node;Node root;void insert(char *a,char *b){int len,i,now,j;Node p=NULL;Node q=NULL;p=root;len=strlen(b);for(i=0;i<len;i++){now=b[i]-'a';if(p->child[now]!=NULL){p=p->child[now];}else{//p=p->child[now];q=(Node)calloc(1,sizeof(node));//q=(node *)malloc(sizeof(root));/*for(j=0;j<26;j++)q->child[j]=NULL;*///strcpy(q->se,"");p->child[now]=q;p=p->child[now];}}strcpy(p->se,a);}char *find(char *s){int len=strlen(s),i,now;Node p;p=root;for(i=0;i<len;i++){now=s[i]-'a';p=p->child[now];if(p==NULL)break;}if(s[i]==0&&strcmp(p->se,""))//不能少return p->se;return 0;}int main(){char s1[100],s2[100],s3[100],str[10000];gets(s3);//root=(Node)malloc(sizeof(node));//root=NULL;root=(Node)calloc(1,sizeof(node));while(scanf("%s",s1)){//getchar();if(!strcmp(s1,"END"))break;scanf("%s",s2);//getchar();insert(s1,s2);}scanf("%s",s3);getchar();while(gets(str)){int i,len=strlen(str),k=0;char temp[10000];if(!strcmp(str,"END"))break;//gets(s2);str[len] = ' ';str[++len] = 0;for(i=0;i<len;i++){if(str[i]>='a'&&str[i]<='z'){temp[k++]=str[i];}else{char *t;temp[k]='\0';t=find(temp);k=0;if(t)printf("%s",t);elseprintf("%s",temp);if(i!=len-1)printf("%c",str[i]);}}printf("\n");}}
0 0
- HDOJ 1075 What Are You Talking About(字典树)
- HDOJ 题目1075What Are You Talking About(字典树)
- HDOJ--1075--What Are You Talking About【字典树】
- HDOJ 1075 What are you talking about ? 字典树
- HDOJ 1075 What Are You Talking About (字典树映射)
- HDU 1075 What Are You Talking About(字典树)
- hdu-1075-What Are You Talking About-(字典树)
- hdu 1075 What Are You Talking About(字典树)
- HDU 1075 What Are You Talking About(字典树)
- hdu 1075 What Are You Talking About(字典树)
- HDU - 1075 - What Are You Talking About(字典树)
- HDU 1075 What Are You Talking About (字典树)
- HDU 1075 What Are You Talking About(字典树)
- HDU 1075 What Are You Talking About(字典树)
- HDOJ 1075 What Are You Talking About
- HDOJ What Are You Talking About 1075
- HDOJ 1075 What Are You Talking About
- hdu 1075 What Are You Talking About (字典树)
- SQL各种连接查询详解(左连接、右连接..)
- php循环控制语句
- hd2036改革春风吹满地
- bzoj1588(平衡树入门题)
- php操作mssql基础
- HDOJ 题目1075What Are You Talking About(字典树)
- 面向对象的三个基本元素,五个基本原则
- OC视频笔记-代理设计模式
- 二维向量的叉乘判断凹凸多边形
- OC视频笔记-引用计数和对象所有权的基本概念
- poj3713 Transferring Sylla 枚举+tarjan判割点
- Linux进程间通信之概述
- 了解Lua语言中的_index,newindex,rawget和rawset
- hdu2000ASCII码排序