Paul Vargas Bautista

ACM TJU Java Solutions

1002. Maya Calendar – Java Solution – ACM TJU

leave a comment »

/*
 * @(#)Main.java	1.00 11/08/2007
 *
 * Copyright 2007 Instituto Tecnológico Superior de Poza Rica
 * http://www.itspozarica.edu.mx
 */
//package

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * The <code>Main</code> class.
 * <p>
 * <a href="http://acm.tju.edu.cn/toj/showp1002.html">Maya Calendar</a>
 *
 * @author Paul Vargas Bautista
 * @version 1.00, 11/08/2007
 */
public final class Main {

    private final Scanner sc;

    private final List<String> namesHaab = this.createNamesHaab();
    private final List<String> namesTzolkin = this.createNamesTzolkin();

    /** Create a new instance of <code>Main</code>. */
    public Main() {
        this.sc = new Scanner(System.in);
        this.solve();
    }

    private int readCase() {
        int day = (int) this.sc.nextFloat();
        int month = this.namesHaab.indexOf(this.sc.next());
        int year = this.sc.nextInt();

        return (year * 365) + (month * 20) + day;
    }

    @SuppressWarnings("nls")
    private void solveCase() {
        int days = this.readCase();
        int year = days / 260;
        int month = days % 20;
        days %= 13;
        System.out.println((days + 1) + " " + this.namesTzolkin.get(month)
                + " " + year);
    }

    private void solve() {
        int cases = this.sc.nextInt();
        System.out.println(cases);
        for (int i = 0; i < cases; i++) {
            this.solveCase();
        }
    }

    @SuppressWarnings("nls")
    private List<String> createNamesHaab() {
        String[] names = { "pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin",
                "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan",
                "pax", "koyab", "cumhu", "uayet" };
        List<String> list = new ArrayList<String>(names.length);
        for (String s : names) {
            list.add(s);
        }
        return list;
    }

    @SuppressWarnings("nls")
    private List<String> createNamesTzolkin() {
        String[] names = { "imix", "ik", "akbal", "kan", "chicchan", "cimi",
                "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix",
                "mem", "cib", "caban", "eznab", "canac", "ahau" };
        List<String> list = new ArrayList<String>(names.length);
        for (String s : names) {
            list.add(s);
        }
        return list;
    }

    /**
     * @param args the arguments in the command line.
     */
    public static void main(String[] args) {
        new Main();
    }

}
About these ads

Written by paulvargas

20120803 at 16:53

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: