天天看點

POJ 2503 Babelfish(map)Babelfish

Babelfish

題目傳送門~

Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 56564 Accepted: 23224

Description

You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.

Input

Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters.

Output

Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".

Sample Input

dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay

atcay
ittenkay
oopslay
      

Sample Output

cat
eh
loops
      

Hint

Huge input and output,scanf and printf are recommended.

Source

Waterloo local 2001.09.22

POJ 2503 Babelfish(map)Babelfish

哈哈哈哈哈哈看!第一道POJ我好菜嗚嗚嗚嗚...不過我會努力的,沖啊啊啊啊AClusir

AC後兩句話:

①這題我切掉後看了好多思路,感覺有一個思路用getchar一個個讀的也超級好!!!附上大哥的傳送門!

②然後這題很簡單嘛...其實就是讓你搞個字典然後查一下,map一下就完事了~(hhhhh昨天看郎朗的綜藝東北話完事了xs)

③這題輸入的組織很重要哇,我是用的gets一起搞進來,再用sscanf分開,超級省事。(不然就要注意空格然後整成兩個循環,大家看情況,這題個人覺得考程式設計的,思路不難叭)

④大家可以學習一下sscanf(部落格很多),我記得我學的時候看到過就注意了一下,現在就用到啦~人生沒有白走的路,每一步都算數!!!(以後有機會我寫個教程,然後你懂得...關注一下你不就學會了嘛嘻嘻嘻嘻)

話不多說,上才藝!!!

#include<iostream>
#include<cstdio>
#include<map>
#include<string>
using namespace std;

map<string,string> dic;//map字典 

int main()
{
	char pre[12],suf[12],str[24];//定義鍵值對字元數組和輸入所需要的變量
	while(gets(str)&&str[0]!='\0'){
		sscanf(str,"%s %s",suf,pre);//按序讀取str,注意中間的空格以及sscanf用法 
		dic[pre]=suf;
	}
	while(gets(str)&&str[0]!='\0'){
		if(dic.count(str))  cout<<dic[str]<<endl;
		else  cout<<"eh"<<endl;		
	}
	return 0;
}
           

繼續閱讀