What Are You Talking About
2015-08-11 17:15
411 查看
[align=left]Problem Description[/align]
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?
[align=left]Input[/align]
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.
[align=left]Output[/align]
In this problem, you have to output the translation of the history book.
[align=left]Sample Input[/align]
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END
[align=left]Sample Output[/align]
hello, i'm from mars.
i like earth!
Hint
Huge input, scanf is recommended.
题解:map解决。强大的STL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <string>
#include <map>
using namespace std;
map<string,string> mp;
char s1[100];
char s2[100];
int main()
{
while(scanf("%s",s1) != EOF)
{
while(scanf("%s",s1) && strcmp(s1,"END") != 0)
{
scanf("%s",s2);
mp[s2] = s1;
}
scanf("%s",s1);
char ch[20];
int k = 0;
char c;
getchar();
while((c = getchar()) && c != 'E')
{
if('a' <= c && c <= 'z')
{
ch[k++] = c;
continue;
}
ch[k] = '\0';
if(mp.count(ch) != 0)
{
cout<<mp[ch];
}
else
{
printf("%s",ch);
}
printf("%c",c);
k = 0;
}
getchar();
getchar();
4000
getchar();
}
return 0;
}
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?
[align=left]Input[/align]
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.
[align=left]Output[/align]
In this problem, you have to output the translation of the history book.
[align=left]Sample Input[/align]
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END
[align=left]Sample Output[/align]
hello, i'm from mars.
i like earth!
Hint
Huge input, scanf is recommended.
题解:map解决。强大的STL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <string>
#include <map>
using namespace std;
map<string,string> mp;
char s1[100];
char s2[100];
int main()
{
while(scanf("%s",s1) != EOF)
{
while(scanf("%s",s1) && strcmp(s1,"END") != 0)
{
scanf("%s",s2);
mp[s2] = s1;
}
scanf("%s",s1);
char ch[20];
int k = 0;
char c;
getchar();
while((c = getchar()) && c != 'E')
{
if('a' <= c && c <= 'z')
{
ch[k++] = c;
continue;
}
ch[k] = '\0';
if(mp.count(ch) != 0)
{
cout<<mp[ch];
}
else
{
printf("%s",ch);
}
printf("%c",c);
k = 0;
}
getchar();
getchar();
4000
getchar();
}
return 0;
}
相关文章推荐
- 网站客户端制作
- 杨柳青青 -by echo
- 内存管理(二)
- Linux开机自启动程序详解
- 养成一个SQL好习惯
- JavaScript Puzzlers (试题)
- 26-网络编程-06-网络编程(域名解析)
- iOS Provisioning Profile(Certificate)与Code Signing详解
- node 纪录
- HTML5的Canvas实现小圆点在屏幕内跑动
- CharSequence与String的区别
- 【Java代码保护技术】代码混淆
- Digit Generator(水)
- StackOverflow程序员推荐:每个程序员都应读的30本书
- CMD:[1]在当前文件夹下打开cmd命令
- Broadcast
- Leetcode#14||Longest Common Prefix
- windows和linux双系统修改启动项顺序
- leetcode 125 —— Valid Palindrome
- gnuplot使用的一些技巧