(字符串,map的使用)What Are You Talking About--HDOJ
2017-08-17 10:35
543 查看
What Are You Talking About
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 250 Accepted Submission(s): 124
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!
Hint
Huge input, scanf is recommended.
Author
Ignatius.L
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 250 Accepted Submission(s): 124
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!
Hint
Huge input, scanf is recommended.
Author
Ignatius.L
/* 自己写的代码一直RE,很无奈,看了别人的思路 但是感觉也说服不了自己,就像词典里有 T i'm 程序跑出来的还是i'm,而不是T,那么也就说明 题目中所给的词典,不存在单词里面有非字母的字符 最近做的题,老是弄错题意,或者根据就理解不了 还有就是想的比较多。。反而弄了很长时间也解决不了问题 总之,做题之前一定要理解好题目,有了思路再写代码,不能边写边想 */ #include<iostream> #include<stdio.h> #include<algorithm> #include<string> #include<string.h> #include<math.h> #include<map> #include<set> #include<string> #define mod 1000000007 using namespace std; int main(void) { freopen("in.txt","r",stdin); map<string ,string> mp; string str,str1; while(cin >> str) { if(!str.compare("START")) continue; if(!str.compare("END")) break; cin >> str1; mp[str1] = str; } cin>>str;//处理掉START getchar();//这里接收一下回车 string str2; while(1) { getline(cin,str2); if(!str2.compare("END")) break; char c[120]; int indx = 0; for(int i=0; i<str2.size(); ++i) { if(islower(str2[i])) c[indx++] = str2[i]; else { c[indx] = '\0'; string s = c; if(mp.count(s)) cout << mp[s]; else cout << s; cout << str2[i]; indx = 0; } } cout << endl; } return 0; }
相关文章推荐
- HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
- HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
- hdoj--1075 What Are You Talking About(Trie or map)
- hdoj1075 What Are You Talking About(STL map处理字符串)
- ACM--火星文--HDOJ 1075--What Are You Talking About--map
- hdoj 1075 What Are You Talking About 【STL map+string】
- HDOJ.1075 What Are You Talking About(map)
- HDOJ 1075 What are you talking about (map + 字符串 )
- (HDU)1075 - What Are You Talking About【字典树】or【字符串map】
- Hdoj 1075 What Are You Talking About 【MAP】
- HDU 1075 What Are You Talking About (map 或者 字典树)
- hdu 1075 What Are You Talking About< map<string,string> >
- hdu 1075 What Are You Talking About map
- HDOJ 1075 -- What Are You Talking About Trie( STL )
- hdoj1075 What Are You Talking About
- hdu/hdoj 1075 What Are You Talking About
- HDOJ 1075 What Are You Talking About(trie树入门)
- hdu 1075 What Are You Talking About(map)
- 【HDOJ】1075 What Are You Talking About
- HDOJ 1075 What Are You Talking About(字典树)