`
Element&lina
  • 浏览: 10372 次
  • 性别: Icon_minigender_1
  • 来自: 目前杭州
社区版块
存档分类
最新评论

PKU1008 calendar conversion

    博客分类:
  • acm
阅读更多
网上看了看,没有对日历转换的特别算法,有个老外建议看看emacs里的实现,
算了,先用这种普通实现得了,除了mapping month name 没发现其他可以优化的。

/**
 * element 20090324
 */
public class CalendarConversion {

	public static final String[] haabMonthsName = { "pop", "no", "zip", "zotz",
			"tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac",
			"kankin", "muan", "pax", "koyab", "cumhu" };

	public static final String[] TzolkinDaysName = { "imix", "ik", "akbal",
			"kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok",
			"chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab",
			"canac", "ahau" };

	public int getMonth(String month) {
		for (int i = 0; i < haabMonthsName.length; i++) {
			if (haabMonthsName[i].equals(month)) {
				if (i == haabMonthsName.length - 1)
					return i * 20 - 15;
				else
					return i * 20;
			}
		}
		return 0;
	}

	public int getdays(String[] dayMonthYear) {
		int year = Integer.parseInt(dayMonthYear[2]);
		int month = this.getMonth(dayMonthYear[1]);
		int day = Integer.parseInt(dayMonthYear[0].substring(0, dayMonthYear[0]
				.length() - 1)) + 1;
		return year * 365 + month + day;
	}

	public String Conversion(String haab) {
		int conuntDay = this.getdays(haab.split(" "));
		String Tzolkin = String.valueOf((conuntDay % 260) % 13) + " "
				+ TzolkinDaysName[(conuntDay % 260) % 20 - 1] + " " + conuntDay / 260;
		return Tzolkin;
	}

	public static void main(String[] args) {
		String haab = "10. zac 1995";
		System.out.println(new CalendarConversion().Conversion(haab));
		//9 cimi 2801
	}

}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics