首页 > 专题系列 > Java解POJ > POJ 1008 Maya Calendar [解题报告] Java
2013
11-08

POJ 1008 Maya Calendar [解题报告] Java

Maya Calendar

问题描述 :

During his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya calendar. From an old knotted message, professor discovered that the Maya civilization used a 365 day long year, called Haab, which had 19 months. Each of the first 18 months was 20 days long, and the names of the months were pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu. Instead of having names, the days of the months were denoted by numbers starting from 0 to 19. The last month of Haab was called uayet and had 5 days denoted by numbers 0, 1, 2, 3, 4. The Maya believed that this month was unlucky, the court of justice was not in session, the trade stopped, people did not even sweep the floor.

For religious purposes, the Maya used another calendar in which the year was called Tzolkin (holly year). The year was divided into thirteen periods, each 20 days long. Each day was denoted by a pair consisting of a number and the name of the day. They used 20 names: imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau and 13 numbers; both in cycles.

Notice that each day has an unambiguous description. For example, at the beginning of the year the days were described as follows:

1 imix, 2 ik, 3 akbal, 4 kan, 5 chicchan, 6 cimi, 7 manik, 8 lamat, 9 muluk, 10 ok, 11 chuen, 12 eb, 13 ben, 1 ix, 2 mem, 3 cib, 4 caban, 5 eznab, 6 canac, 7 ahau, and again in the next period 8 imix, 9 ik, 10 akbal . . .

Years (both Haab and Tzolkin) were denoted by numbers 0, 1, : : : , where the number 0 was the beginning of the world. Thus, the first day was:

Haab: 0. pop 0

Tzolkin: 1 imix 0

Help professor M. A. Ya and write a program for him to convert the dates from the Haab calendar to the Tzolkin calendar.

输入:

The date in Haab is given in the following format:

NumberOfTheDay. Month Year

The first line of the input file contains the number of the input dates in the file. The next n lines contain n dates in the Haab calendar format, each in separate line. The year is smaller then 5000.

输出:

The date in Tzolkin should be in the following format:

Number NameOfTheDay Year

The first line of the output file contains the number of the output dates. In the next n lines, there are dates in the Tzolkin calendar format, in the order corresponding to the input dates.

样例输入:

3
10. zac 0
0. pop 0
10. zac 1995

样例输出:

3
3 chuen 0
1 imix 0
9 cimi 2801

解题代码:

import java.util.Scanner;

 public class Main {

     public static void main(String[] args) {
         Scanner scan = new Scanner(System.in);
         int times = scan.nextInt();
         System.out.println(times);
         int day;
         int day2;
         int t_day = 0;
         int t_month;
         String month;
         String month2;
         int year;
         int year2;
         int day_num;
         int day_num2;
         for (int i = 0; i < times; i++) {
             String str_day = scan.next();
             day = Integer.parseInt(str_day.substring(0, str_day.length() - 1));
             month = scan.next();
             year = scan.nextInt();
             t_month = getHaabMonth(month);
             if(t_month<=18){
                 t_day = (t_month-1) * 20;
             }else{
                 t_day = 360;
             }
             day_num = 365 * year  +  t_day + (day + 1);
             year2 = day_num / 260;
             day_num2 = day_num % 260;
             if(day_num2 == 0){
                 year2--;
             }
             day2 = day_num2 % 13;
             if (day2 == 0) {
                 day2 = 13;
             }
             month2 = getTzolkinMonth(day_num2 % 20);
             System.out.println(day2 + " " + month2 + " " + year2);
         }
     }

     public static int getHaabMonth(String month) {
         if (month.equals("pop")) {
             return 1;
         } else if (month.equals("no")) {
             return 2;
         } else if (month.equals("zip")) {
             return 3;
         } else if (month.equals("zotz")) {
             return 4;
         } else if (month.equals("tzec")) {
             return 5;
         } else if (month.equals("xul")) {
             return 6;
         } else if (month.equals("yoxkin")) {
             return 7;
         } else if (month.equals("mol")) {
             return 8;
         } else if (month.equals("chen")) {
             return 9;
         } else if (month.equals("yax")) {
             return 10;
         } else if (month.equals("zac")) {
             return 11;
         } else if (month.equals("ceh")) {
             return 12;
         } else if (month.equals("mac")) {
             return 13;
         } else if (month.equals("kankin")) {
             return 14;
         } else if (month.equals("muan")) {
             return 15;
         } else if (month.equals("pax")) {
             return 16;
         } else if (month.equals("koyab")) {
             return 17;
         } else if (month.equals("cumhu")) {
             return 18;
         } else if (month.equals("uayet")) {
             return 19;
         } else {
             return 0;
         }
     }

     public static String getTzolkinMonth(int month) {
         if (month == 1) {
             return "imix";
         } else if (month == 2) {
             return "ik";
         } else if (month == 3) {
             return "akbal";
         } else if (month == 4) {
             return "kan";
         } else if (month == 5) {
             return "chicchan";
         } else if (month == 6) {
             return "cimi";
         } else if (month == 7) {
             return "manik";
         } else if (month == 8) {
             return "lamat";
         } else if (month == 9) {
             return "muluk";
         } else if (month == 10) {
             return "ok";
         } else if (month == 11) {
             return "chuen";
         } else if (month == 12) {
             return "eb";
         } else if (month == 13) {
             return "ben";
         } else if (month == 14) {
             return "ix";
         } else if (month == 15) {
             return "mem";
         } else if (month == 16) {
             return "cib";
         } else if (month == 17) {
             return "caban";
         } else if (month == 18) {
             return "eznab";
         } else if (month == 19) {
             return "canac";
         } else if (month == 0) {
             return "ahau";
         } else {
             return "";
         }
     } 
}

  1. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.