您的位置:首页 > 编程语言 > Java开发

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

2016-07-20 03:19 337 查看
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);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: