【算法笔记】B1044 火星数字
生活随笔
收集整理的這篇文章主要介紹了
【算法笔记】B1044 火星数字
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1044?火星數(shù)字?(20?分)
火星人是以 13 進(jìn)制計(jì)數(shù)的:
- 地球人的 0 被火星人稱為 tret。
- 地球人數(shù)字 1 到 12 的火星文分別為:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。
- 火星人將進(jìn)位以后的 12 個(gè)高位數(shù)字分別稱為:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。
例如地球人的數(shù)字?29?翻譯成火星文就是?hel mar;而火星文?elo nov?對(duì)應(yīng)地球數(shù)字?115。為了方便交流,請(qǐng)你編寫程序?qū)崿F(xiàn)地球和火星數(shù)字之間的互譯。
輸入格式:
輸入第一行給出一個(gè)正整數(shù)?N(<),隨后?N?行,每行給出一個(gè) [0, 169) 區(qū)間內(nèi)的數(shù)字 —— 或者是地球文,或者是火星文。
輸出格式:
對(duì)應(yīng)輸入的每一行,在一行中輸出翻譯后的另一種語(yǔ)言的數(shù)字。
輸入樣例:
4 29 5 elo nov tam輸出樣例:
hel mar may 115 13思路:
直接計(jì)算出所有數(shù)字的映射,就可以直接查詢輸出了。13的倍數(shù)對(duì)應(yīng)的火星數(shù)字是tam,hel,maa…而不是tam tret,hel tret,maa?tret…
?codes:
1 #include <bits/stdc++.h> 2 using namespace std; 3 string str1[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; 4 string str2[13] = {"", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"}; 5 map<int, string> toMars; 6 map<string, int> toNums; 7 void init(){ 8 for(int i = 0; i < 13; i++){ 9 toMars[i] = str1[i]; 10 toNums[str1[i]] = i; 11 } 12 for(int i = 13; i < 169; i++){ 13 string s; 14 if(i%13 == 0) s = str2[i / 13]; 15 else s = str2[i / 13] + ' ' + str1[i % 13]; 16 toMars[i] = s; 17 toNums[toMars[i]] = i; 18 } 19 } 20 21 int main(){ 22 init(); 23 int n; 24 scanf("%d", &n); 25 getchar(); 26 for(int i = 0; i < n; i++){ 27 string str; 28 getline(cin, str); 29 if(str[0]>='0'&&str[0]<='9'){ 30 int num = 0; 31 for(int j = 0; j < str.length(); j++){ 32 num = num * 10 + (str[j] - '0'); 33 } 34 cout<<toMars[num]<<endl; 35 }else{ 36 cout<<toNums[str]<<endl; 37 } 38 } 39 return 0; 40 }?
轉(zhuǎn)載于:https://www.cnblogs.com/chunlinn/p/10631737.html
總結(jié)
以上是生活随笔為你收集整理的【算法笔记】B1044 火星数字的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: FIFO buffer 和普通buffe
- 下一篇: 章节七、4-Sets