PAT 甲級 1100 Mars Numbers (20分)

People on Mars count their numbers with base 13:

Zero on Earth is called "tret" on Mars.

The numbers 1 to 12 on Earth is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, respectively.

For the next higher digit, Mars people name the 12 numbers as "tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou", respectively.

For examples, the number 29 on Earth is called "hel mar" on Mars; and "elo nov" on Mars corresponds to 115 on Earth. In order to help communication between people from these two planets, you are supposed to write a program for mutual translation between Earth and Mars number systems.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive integer?N?(<100). Then?N?lines follow, each contains a number in [0, 169), given either in the form of an Earth number, or that of Mars.

Output Specification:

For each number, print in a line the corresponding number in the other language.

Sample Input:

4

29

5

elo nov

tam

Sample Output:

要點(diǎn):進(jìn)制轉(zhuǎn)換

易錯(cuò)點(diǎn):轉(zhuǎn)換成Mars Numbers時(shí)? 個(gè)位的tret省略

示例:

#include <iostream>

#include <string>

#include <sstream>

using namespace std;

string base1[13] = {"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};

string base2[12] = { "tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou" };

int getIndex1(string str)

{

????for (int i = 0; i < 13; ++i)

????????if (str == base1[i])

????????????return i;

????return -1;

}

int getIndex2(string str)

{

????for (int i = 0; i < 12; ++i)

????????if (str == base2[i])

????????????return i + 1;

????return -1;

}

void test()

{

????int N;

????cin >> N;

????getchar();

????for (int i = 0; i < N; ++i)

????{

????????string str;

????????getline(cin, str);

????????if (isdigit(str[0]))

????????{

????????????int num = stoi(str);

????????????if (num > 12)???

? ? ? ? ? ? {

????????????? ? ? if(num%13==0)

? ? ? ? ? ? ? ? ? cout << base2[num / 13 - 1]<< endl;

? ? ? ? ? ? ? ? ? else

? ? ? ? ? ? ? ? ? cout << base2[num / 13 - 1] << " " << base1[num % 13] << endl;

? ? ? ? ? ? }

? ? ? ? ? ? else

????????????????cout << base1[num] << endl;

????????}

????????else

????????{

????????????int num = 0;

????????????int result = 0;

????????????istringstream iss(str);

????????????while (iss >> str)

????????????{

????????????????num=(getIndex1(str) > getIndex2(str) ? getIndex1(str) : getIndex2(str));

????????????????if (getIndex2(str) > 0)

????????????????????result += (13 * num);

????????????????else

????????????????????result += num;

????????????}

????????????cout << result << endl;

????????}

????}

}

int main()

{

????test();

????system("pause");

????return 0;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市宏怔,隨后出現(xiàn)的幾起案子菜皂,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件银还,死亡現(xiàn)場離奇詭異努隙,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)哀九,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進(jìn)店門剿配,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人阅束,你說我怎么就攤上這事呼胚。” “怎么了息裸?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵蝇更,是天一觀的道長。 經(jīng)常有香客問我呼盆,道長年扩,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任访圃,我火速辦了婚禮厨幻,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘腿时。我一直安慰自己况脆,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布批糟。 她就那樣靜靜地躺著格了,像睡著了一般。 火紅的嫁衣襯著肌膚如雪徽鼎。 梳的紋絲不亂的頭發(fā)上盛末,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天弹惦,我揣著相機(jī)與錄音,去河邊找鬼悄但。 笑死肤频,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的算墨。 我是一名探鬼主播宵荒,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼净嘀!你這毒婦竟也來了报咳?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤挖藏,失蹤者是張志新(化名)和其女友劉穎暑刃,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體膜眠,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡岩臣,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了宵膨。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片架谎。...
    茶點(diǎn)故事閱讀 39,785評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖辟躏,靈堂內(nèi)的尸體忽然破棺而出谷扣,到底是詐尸還是另有隱情,我是刑警寧澤捎琐,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布会涎,位于F島的核電站,受9級特大地震影響瑞凑,放射性物質(zhì)發(fā)生泄漏末秃。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一籽御、第九天 我趴在偏房一處隱蔽的房頂上張望练慕。 院中可真熱鬧,春花似錦篱蝇、人聲如沸贺待。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至秃臣,卻和暖如春涧衙,著一層夾襖步出監(jiān)牢的瞬間哪工,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工弧哎, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留雁比,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓撤嫩,卻偏偏與公主長得像偎捎,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子序攘,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,713評論 2 354