代码
#include <iostream>
#include <sstream>
using namespace std;
const int RADIX = 13;
string zeroToTwelve[] = {"tret", "jan", "feb", "mar", "apr", "may", "jun",
"jly", "aug", "sep", "oct", "nov", "dec"};
string thirteenTo169[] = {"", "tam", "hel", "maa", "huh", "tou", "kes", "hei",
"elo", "syy", "lok", "mer", "jou"};
int stringToInt(string t) {
stringstream ss;
ss<<t;
int tmp;
ss>>tmp;
return tmp;
}
string numToStr(int n) {
string ans;
if(n<RADIX) {
ans += zeroToTwelve[n%RADIX];
} else {
ans += thirteenTo169[n/RADIX];
if(n%RADIX) {
ans += " ";
ans += zeroToTwelve[n%RADIX];
}
}
return ans;
}
int strToNum(string s) {
int ans = 0;
if(s.compare("tret")==0) {
return 0;
} else if(s.length()>3) {
string s1 = s.substr(0, 3);
string s2 = s.substr(4);
for(int i=0; i<RADIX; i++) {
if(s1.compare(thirteenTo169[i])==0) {
ans += RADIX*i;
}
if(s2.compare(zeroToTwelve[i])==0) {
ans += i;
}
}
} else {
for(int i=0; i<RADIX; i++) {
if(s.compare(zeroToTwelve[i])==0) {
ans += i;
}
if(s.compare(thirteenTo169[i])==0) {
ans += RADIX*i;
}
}
}
return ans;
}
int main() {
string str;
getline(cin, str);
int n = stringToInt(str);
for(int i=0; i<n; i++) {
string s1;
getline(cin, s1);
if(s1.at(0)>='0' && s1.at(0)<='9') {
cout<<numToStr(stringToInt(s1))<<endl;
} else {
cout<<strToNum(s1)<<endl;
}
}
return 0;
}
注解
需要注意的是13的整数倍的输出,不需要多余的0。
如:13只需要输出tam,而不是tam tret。也不要有多余空格。