解析:1.判斷輸入的是數字還是火星文
- 2.數字如果長度>13那麼就是有高位 否則低位,要注意13的倍數低位都是0,因爲13進1
- 3.火星文要判斷是都是帶高位的,也就是是否長度>3的
public class Pta_1044 {
//0-12的火星文
public static String[] s1 = new String[]{"tret", "jan", "feb", "mar", "apr", "may", "jun",
"jly", "aug", "sep", "oct", "nov", "dec"};
//高位1-12的火星文
public static String[] s2 = new String[]{"tam", "hel", "maa", "huh", "tou", "kes",
"hei", "elo", "syy", "lok", "mer", "jou"};
public static void main(String[] args) throws IOException {
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
int time = Integer.parseInt(buf.readLine());
for (int i = 0; i < time; i++) {
String s = buf.readLine();
chek(s);
}
}
public static void chek(String s) {
//判斷輸入的是數字還是火星文
if ('0' <= s.charAt(0) && s.charAt(0) <= '9') {//輸入是數字
int ss = Integer.parseInt(s);
int a = 0;//低位
int b = 0;//高位
//數字如果 >13那麼就是有高位 否則低位
if (ss == 0) {
System.out.println("tret");
} else {
if (ss < 13) {//沒有高位
a = ss % 13;//得十進制數
System.out.println(s1[a]);
}
if(12<ss&&ss<169) {//有高位
b = ss / 13;//高
a = ss - b * 13;//低
if (a == 0) {
System.out.println(s2[b - 1]);
} else {
System.out.println(s2[b - 1] + " " + s1[a]);
}
}
}
} else {//輸入是火星文 火星文要判斷是否是帶高位的,也就是是否長度>3的
if (s.equals("tret")) {
System.out.println(0);
} else {
if (s.length() > 3) {
String[] split = s.split(" ");
String s3 = split[0];//高位
String s4 = split[1];//低位
int res = 0;
for (int i = 0; i < s2.length; i++) {
if (s2[i].equals(s3)) {
res = (i + 1) * 13;//8 11
}
}
for (int i = 0; i < s1.length; i++) {
if (s1[i].equals(s4)) {
res = res + i;
}
}
System.out.println(res);
} else {//低位
int a,b;
for (int i = 0; i < s1.length; i++) {
if (s1[i].equals(s)) {
System.out.println(i);
}
}
//如果是直接高位
for (int i = 0; i < s2.length; i++) {
if (s2[i].equals(s)) {
System.out.println((i + 1) * 13);//8 11
}
}
}
}
}
}
}