PAT Advanced 1100 Mars Numbers (20 )
题目描述
Input Specification:
Output Specification:
Sample Input:
Sample Output:
解题思路
一度怀疑我的语文阅读理解能力。。tam是13竟然是因为0不输出。。我一直以为是13-24是用高进制的数表示。。知道真相的我气到昏厥。。
Code
- AC代码
#include<bits/stdc++.h>
using namespace std;
string unit1[] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string unit2[] = {"tret", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
void earth2mars(string str){
int number = stoi(str);
if(number < 13) {
cout << unit1[number] << '\n';
} else {
cout << unit2[number/13];
if(number%13) {
cout << " " << unit1[number%13];
}
cout << '\n';
}
}
void mars2earth(string str) {
int res = 0;
string tem1 = str, tem2 = "";
int spaceIndex = str.find(' ');
if(spaceIndex != -1) {
tem1 = str.substr(0, spaceIndex);
tem2 = str.substr(spaceIndex+1, str.length()-spaceIndex-1);
}
for(int i = 0; i<13; i++) {
if(tem1 == unit1[i]) {
res = i;
break;
}
else if(tem1 == unit2[i]) {
res = i*13;
if(tem2.length()) {
for(int j = 0; j<13; j++) {
if(tem2 == unit1[j]) {
res += j;
}
}
}
break;
}
}
cout << res << '\n';
}
int main() {
//freopen("in.txt", "r", stdin);
int N;
cin >> N;
getchar();
string temp;
for(int i = 0; i<N; i++) {
getline(cin, temp);
if(temp[0]>='0' && temp[0]<='9') {
earth2mars(temp);
} else {
mars2earth(temp);
}
}
return 0;
}