1008 Maya Calendar_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 1008 Maya Calendar

1008 Maya Calendar

 2012/3/17 15:26:37  s1099  程序员俱乐部  我要评论(0)
  • 摘要:不同计年方法之间的转化,我的思路是:根据各自计年方法的定义,将一种计年方法换算成总天数,再将总天数转化为令一种计年方法。importjava.util.*;importjava.io.*;//1008MayaCalendarpublicclassMain{staticfinalString[]Haab={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin"
  • 标签:

? ? ? 不同计年方法之间的转化,我的思路是:根据各自计年方法的定义,将一种计年方法换算成总天数,再将总天数转化为令一种计年方法。

import java.util.*;
import java.io.*;
//1008 Maya Calendar
public class Main 
{
	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"};

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(new BufferedInputStream(System.in));

		String line = in.nextLine();
		System.out.println(line);

		int countOfCase = Integer.parseInt(line);
		int dotPos, lastSpacePos,
			num, month, year,
			worldDay;

		while(countOfCase-- > 0) {
			worldDay = 0;
			line = in.nextLine();
			dotPos = line.indexOf('.');
			lastSpacePos = line.lastIndexOf(' ');
			
			num = Integer.parseInt(line.substring(0, dotPos));
			month = getMonth(line.substring(dotPos+2, lastSpacePos));
			year = Integer.parseInt(line.substring(lastSpacePos+1));

			worldDay += (year*365 + num);
			if(month > 0)
				worldDay += month*20;

			System.out.printf("%d %s %d\n", (worldDay%260)%13 + 1, Tzolkin[(worldDay%260)%20], worldDay/260);
		}
	}

	public static int getMonth(String monthStr) {
		for(int i = 0; i < Haab.length; i++) {
			if(Haab[i].equals(monthStr))
				return i;
		}
		return -1;
	}
}
?
  • 相关文章
发表评论
用户名: 匿名