[pku] 1008 Maya Calendar
2008/03/30
java
pku
poj
問題文が長がそうだったので後回しにしていたのをチャレンジ。
マヤのカレンダー
なんかちょっとオカルトっぽい、説があるようで、何か近寄りがたいなマヤカレンダー。
解き方は、えーと、Haabで与えられた値から日にちをもとめて、日にちから、Tzolkinを求めるという方法。
package p1008;
import java.util.Scanner;
import java.util.regex.MatchResult;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
System.out.println(n);
for (int i = 0; i < n; i++) {
scanner.findInLine("(\\d+)\\. ([a-z]+) (\\d+)");
MatchResult result = scanner.match();
int pos = 1;
int d = Haab(Integer.parseInt(result.group(pos++)), result
.group(pos++), Integer.parseInt(result.group(pos++)));
System.out.println(Tzolkin(d));
}
}
static int Haab(int d, String m, int y) {
y = y * 365;
int mm = monthOfHaab(m);
return d + (20 * mm) + y;
}
static String Tzolkin(int d) {
int m = d % 20;
int nd = (d % 13) + 1;
int y = (d / 20) / 13;
return String.format("%d %s %d", nd, Tzolkin[m], y);
}
static int monthOfHaab(String s) {
for (int i = 0; i < Haab.length; i++) {
if (Haab[i].equals(s))
return i;
}
throw new RuntimeException("not found Haab month...");
}
static int Tzolkin(String s) {
for (int i = 0; i < Tzolkin.length; i++) {
if (Tzolkin[i].equals(s))
return i + 1;
}
throw new RuntimeException("not found Tzolkin month...");
}
static final String[] Haab = { "pop", "no", "zip", "zotz", "tzec", "xul",
"yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin",
"muan", "pax", "koyab", "cumhu", "uayet" };
static final String[] Tzolkin = { "imix", "ik", "akbal", "kan", "chicchan",
"cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben",
"ix", "mem", "cib", "caban", "eznab", "canac", "ahau" };
}
import java.util.Scanner;
import java.util.regex.MatchResult;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
System.out.println(n);
for (int i = 0; i < n; i++) {
scanner.findInLine("(\\d+)\\. ([a-z]+) (\\d+)");
MatchResult result = scanner.match();
int pos = 1;
int d = Haab(Integer.parseInt(result.group(pos++)), result
.group(pos++), Integer.parseInt(result.group(pos++)));
System.out.println(Tzolkin(d));
}
}
static int Haab(int d, String m, int y) {
y = y * 365;
int mm = monthOfHaab(m);
return d + (20 * mm) + y;
}
static String Tzolkin(int d) {
int m = d % 20;
int nd = (d % 13) + 1;
int y = (d / 20) / 13;
return String.format("%d %s %d", nd, Tzolkin[m], y);
}
static int monthOfHaab(String s) {
for (int i = 0; i < Haab.length; i++) {
if (Haab[i].equals(s))
return i;
}
throw new RuntimeException("not found Haab month...");
}
static int Tzolkin(String s) {
for (int i = 0; i < Tzolkin.length; i++) {
if (Tzolkin[i].equals(s))
return i + 1;
}
throw new RuntimeException("not found Tzolkin month...");
}
static final String[] Haab = { "pop", "no", "zip", "zotz", "tzec", "xul",
"yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin",
"muan", "pax", "koyab", "cumhu", "uayet" };
static final String[] Tzolkin = { "imix", "ik", "akbal", "kan", "chicchan",
"cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben",
"ix", "mem", "cib", "caban", "eznab", "canac", "ahau" };
}
: