hdu 1075 What Are You Talking About(HashMap水过,可用字典树)

来源:互联网 发布:福州市网络家长学校 编辑:程序博客网 时间:2024/06/05 03:18

What Are You Talking About

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


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!
Hint
Huge input, scanf is recommended.
 

import java.util.HashMap;import java.util.Scanner;public class Main{//用HashMap水过,可以用字典树public static void main(String[] args) {Scanner input=new Scanner(System.in);String s=input.next();HashMap<String,String> map=new HashMap<String, String>();while(!(s=input.next()).equals("END")){String str=input.next();map.put(str, s);}s=input.next();String sss=input.nextLine();while(true){String s2=input.nextLine();if(s2.equals("END"))break;boolean ok=true;int x=0;for(int i=0;i<s2.length();i++){char a=s2.charAt(i);if(a>='a'&&a<='z'){if(ok){x=i;ok=false;}}else{if(ok==false){String s1=s2.substring(x,i);if(map.get(s1)!=null){System.out.print(map.get(s1));}elseSystem.out.print(s1);}System.out.print(a);ok=true;}}System.out.println();}}}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 在暴风影音上视频播放不出来怎么办 格式工厂转换格式占内存太大怎么办 手机登陆不上路由器管理界面怎么办 新路由器设置密码后不能上网怎么办 更换网络后无线路由器不能用怎么办 手机登录不了路由器登录业面怎么办 海康威视通道用户被锁定怎么办 无线适配器或访问点有问题怎么办 客户买鞋子说价格贵该怎么办 小米5s刷成真砖后怎么办 手机电源键坏了开不了机怎么办 手机开关键坏了开不了机怎么办 vivo手机解屏密码忘了怎么办 小米max关机后开关键坏了怎么办 联想手机刷机失败无限重启怎么办 红米2a显示白屏怎么办 小米6手机一直处于开机状态怎么办 怎么在手机上看wifi密码怎么办 怎么查自己的宽带密码忘记了怎么办 怎么查自己宽带账号密码忘了怎么办 电脑重置路由器密码连不上网怎么办 e盘和f盘没有了怎么办 复制文件过程中自己卡住了怎么办 电脑卡住了怎么办 鼠标也点不动 善领wifi连上网不能用怎么办 苹果手机软件更新后网速太慢怎么办 装了固态硬盘开机还慢怎么办 华为荣耀8青春版玩游戏卡怎么办 光猫自带wifi网络很差怎么办 侠盗猎车手自由城之章卡退怎么办? 夏天带头盔晃眼睛太厉害怎么办 别人把钱误转我卡上我怎么办? 家里预留的的网线太短怎么办 电信路由器坏了网线接口断了怎么办 数据线充手机的接头处断了怎么办 新买的小米手环充不进去电怎么办 绝地求生手游被队友故意炸死怎么办 一加3t屏幕开了怎么办? 孕妇吃了8个杏怎么办啊 洗碗盆落水器垫子密封不好怎么办? 手剥橙子剥的特别疼怎么办?