题意:
相当于进制转换,给出0-12和13的倍数对应的火星文,即tam对应13,hel对应26,等等依次对应。pat不能用gets();
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
const int maxn = 20;
using namespace std;
void toMars(char s[]);
void toDigit(char s[]);
string low[13] = {"tret", "jan", "feb", "mar", "apr", "may",
"jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string up[13] = {"", "tam", "hel", "maa", "huh", "tou", "kes",
"hei", "elo", "syy", "lok", "mer", "jou"};
int main(int argc, char** argv) {
int n;
scanf("%d", &n);
getchar();
char str[maxn];
string t;
while(n--) {
int i = 0;
while(scanf("%c", str[i++]) && (str[i - 1] != '\n' || str[i - 1] != EOF));
str[i] = '\0';
if (str[0] >= '0' && str[0] <= '9')
toMars(str);
else
toDigit(str);
}
return 0;
}
void toMars(char s[]) {
int sum = 0;
for (int i = 0; i < strlen(s); i++) {
sum += (s[i] - '0') * 10;
}
int h = sum / 13;
int mod = sum % 13;
string ans = h == 0 ? low[mod] : up[h] + " " + low[mod];
printf("%s\n", ans.c_str());
}
void toDigit(char s[]) {
string str(s);
int index = str.find(' ');
string s1 = str.substr(0, index);
string s2 = str.substr(index + 1, str.size() - index - 1);
int sum = 0, i;
if (s1.size() != 0) {
for (i = 1; i < 13; i++)
if (up[i].compare(s1) == 0) {
sum += 13 * i;
break;
}
}
for (i = 0; i < 13; i++) {
if (low[i].compare(s2) == 0) {
sum += i;
break;
}
}
printf("%d\n", sum);
}