PAT_B_1044_Java(20分)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine());
		String[] s1 = { "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec" };
		String[] s2 = { "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };
		for (int i = 0; i < n; i++) {
			String s = bf.readLine();
			int r = 0;
			int a1, a2;
			if (s.matches("[0-9]{1,}")) {
				r = Integer.valueOf(s);
				if (r == 0) {
					System.out.println("tret");
					continue;
				}
				if (r < 13) {
					a1 = r % 13;
					System.out.println(s1[a1 - 1]);
				}
				if (12 < r && r < 169) {
					a2 = r / 13;
					a1 = r - a2 * 13;
					if (a1 == 0) {
						System.out.println(s2[a2 - 1]);
					} else {
						System.out.println(s2[a2 - 1] + " " + s1[a1 - 1]);
					}

				}
			} else {
				if (s.equals("tret")) {
					System.out.println(0);
					continue;
				}
				String[] split = s.split(" ");
				if (split.length != 1) {
					a1 = getIndex(s1, split[1]);
					a2 = getIndex(s2, split[0]);
					System.out.println(a2 * 13 + a1);
				} else {
					a1 = getIndex(s1, split[0]);
					a2 = getIndex(s2, split[0]);
					if (a1 != 0) {
						System.out.println(a1);
					} else {
						System.out.println(a2 * 13);
					}

				}
			}
		}
	}

	public static int getIndex(String[] arr, String value) {
		for (int i = 0; i < arr.length; i++) {
			if (arr[i].equals(value)) {
				return i + 1;
			}
		}
		return 0;
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值