People on Mars count their numbers with base 13:
- Zero on Earth is called "tret" on Mars.
- The numbers 1 to 12 on Earch 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:地球数用的是10进制的阿拉伯数字,
火星数用的是13进制的。且低位表示0~12为tret……dec 而高位13,26,39……13*12为tam……jou。注意,当地球数为13的倍数,只要高位的即可
这次2015pat的20分,考试的时候只过了两个测试点,当时也是下面的思路,应该是/%12、13出现遗漏,还有就是用惯了vs换成vc6有点不熟悉。
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
9月12日 19:23 | 答案正确 | 20 | 1100 | C++ (g++ 4.7.2) | 1 | 308 | datrilla |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 180 | 12/12 |
1 | 答案正确 | 1 | 308 | 2/2 |
2 | 答案正确 | 1 | 300 | 2/2 |
3 | 答案正确 | 1 | 308 | 2/2 |
4 | 答案正确 | 1 | 180 | 2/2 |
#include<iostream> #include<string> using namespace std; int equelstr(string *mars, string str) { int i; for (i = 0; i < 25 && mars[i] != str; i++); return i; } int main() { string mars[25] = { "tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" }; string str,strt; int N, num,temp,goal; cin >> N; getchar(); while (N--) { getline(cin, str); if (str[0] >= '0'&&str[0] <= '9' ) { sscanf(str.c_str(), "%d", &num); if (num < 13 || num>12 && num % 13 == 0) cout << mars[num%13+(num>12?num/13+12:0)] << endl; else cout << mars[num / 13+12] << " " << mars[num % 13] << endl; } else { temp = str.find(' '); if (temp != -1) { strt = str.substr(0,3); goal = (equelstr(mars, strt)-12)*13; strt = str.substr(temp+1,3); goal += equelstr(mars, strt); } else { goal=equelstr(mars, str); goal = goal > 12 ? (goal - 12) * 13 : goal; } cout << goal << endl; } } system("pause"); return 0; }