ZOJ 1109 Language of FatMouse

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   os   io   strong   

最近學的線段樹和掃描線實在是有點難度,所以我乾脆拿出點時間寫篇自己之前做的題目報告吧!

                                                     Language of FatMouse

Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%lld & %lluSubmit Status Practice ZOJ 1109

Description

We all know that FatMouse doesn‘t speak English. But now he has to be prepared since our nation will join WTO soon. Thanks to Turing we have computers to help him.

Input Specification

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

Output Specification

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

Sample Input
dog ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay
Output for Sample Input
catehloops

演算法分析:
學過演算法的話,能看出來這道題應該用字典樹做,我個人覺得除非功底非常強,否則單槍匹馬
敲出針對題目的字典樹來其實還真不容易。由於最近學習了STL,所以我選擇用STL來做,這樣代
碼比較簡潔,也容易看懂。我個人覺得,你只要把題意弄懂,清楚針對題目的演算法,用STL來描述
演算法還是比較容易、方便、快捷的!
本題的題意是:每行輸入兩個單詞a, b; a是正常單詞,b是胖老鼠語言(獸語吧)!
然後有多組詢問:每組給你獸語,讓你輸出對應這個獸語的正常單詞。
我選擇用STL的map來做,開始時我以為map可以這樣定義:map<string, string>,我第一
次的代碼是這麼寫的但編譯不過去。於是趕緊查資料發現好多模板裡的map定義都包含int,沒有我
剛才的那種定義。我這是突然想起來,記得在描述map時,說它是:鍵——值的類型。所以那個值好像
就是int類型的。
所以這道題,我定義map<string, int>類型,再額外開闢一個 char s[][]; 用來儲存正常
語言 。就像這樣:
讀入s1,s2;
e=1;
map[s2]=e++; // map的值是存到二維數組裡的下標
strcpy(s[e-1], s1 );
詢問時,讀入s3,if(map[s3>0]), 直接輸出map[s3]
否則,,,,,,,,
Accepted的代碼:
#include <stdio.h>#include <string.h>#include <string>#include <map>#include <algorithm>using namespace std;char s1[20], s2[20], s3[20];char s[100007][15];int main(){map<string, int>ma;map<string, int>::iterator it;    int e=1;    while(scanf("%c", &s1[0]) && s1[0]!=‘\n‘ ){scanf("%s %s%*c", s1+1, s2 );ma[s2]=e++ ;strcpy(s[e-1], s1);}    int flag;    while(scanf("%s", s3)!=EOF){    if(ma[s3]>=1){printf("%s\n", s[ma[s3]] );}if(ma[s3]==0){printf("eh\n");}} return 0;}

 



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.