算法日记(Java实现)第20160719(5)期——POJ1008

POJ1008
题目地址:http://poj.org/problem?id=1008
本题虽然思路很简单。却连续提交了七次,花费了大量时间检查错误才通过。主要是没有足够重视题目中的细节。

源代码如下:

import java.util.Scanner;

//POJ 1008

/*Date: 2016.07.19
* 1st:	Compile Error	J2SE不支持String使用switch语句
* 2nd:  Runtime Error	月份算错
* 3rd:	Wrong Answer	未打印n
* 4th:  Wrong Answer	日期算错
* 5th:  Wrong Answer	
* 6th:  Wrong Answer
* 7th:  Accepted
*/

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		System.out.println(n);
		for (int i = 0; i < n; i++) {
			String day_ = sc.next();
			int day = Integer.decode(day_.substring(0, day_.indexOf('.')));
			String month_ = sc.next();
			int year = sc.nextInt();
			if (month_.equals("pop") ){
				day += 0;
			} else if (month_.equals("no")) {
				day += 20;
			} else if (month_.equals("zip")) {
				day += 20 * 2;
			} else if (month_.equals("zotz")) {
				day += 20 * 3;
			} else if (month_.equals("tzec") ){
				day += 20 * 4;
			} else if (month_.equals("xul") ){
				day += 20 * 5;
			} else if (month_.equals("yoxkin")) {
				day += 20 * 6;
			} else if (month_.equals("mol") ){
				day += 20 * 7;
			} else if (month_.equals("chen") ){
				day += 20 * 8;
			} else if (month_.equals("yax") ){
				day += 20 * 9;
			} else if (month_.equals("zac") ){
				day += 20 * 10;
			} else if (month_.equals("ceh") ){
				day += 20 * 11;
			} else if (month_.equals("mac") ){
				day += 20 * 12;
			} else if (month_.equals("kankin")) {
				day += 20 * 13;
			} else if (month_.equals("muan") ){
				day += 20 * 14;
			} else if (month_.equals("pax") ){
				day += 20 * 15;
			} else if (month_.equals("koyab")) {
				day += 20 * 16;
			} else if (month_.equals("cumhu") ){
				day += 20 * 17;
			} else {
				day += 20 * 18;
			}
			day += (year * 365 + 1);
			int tyear = day / 260;
			if(day != 0 && day % 260 == 0)
				tyear--;
			int number = day % 13;
			if(number == 0)
				number = 13;
			String[] ar = { "imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen",
					"eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau" };
			String name;
			if(day % 20 != 0)
				name = ar[day % 20 - 1];
			else
				name = ar[19];
			System.out.println(number + " " + name + " " + tyear);
		}
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值