POJ1008

理解题意之后很容易得到两个日历之间的换算,但是要注意holly日历最后一天的计算,如当经过了260的倍数天数时,holly日历如何显示呢?

#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n,year,number,*holly_year,*holly_a,*holly_b;
	string day, month;
	string haab_year[19] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", 
	"chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu", "uayet"},
	holly_word[21] = {"", "imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", 
	"eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};
	scanf("%d", &n);
	holly_a = new int[n];
	holly_b = new int[n];
	holly_year = new int[n];
	for (int i = 0; i < n; i++) {
		number = 0;
		cin >> day >> month >> year;
		number += year * 365;
		for (int j = 0; j < 19; j++) {
			if (month == haab_year[j]) {
				number += 20*j;
				break;
			}
		}
		day = day.substr(0,day.length()-1);
		number += atoi(day.c_str())+1;	
		holly_year[i] = number / 260;
		number %= 260;
		if (number == 0) {
			holly_a[i] = 13;
			holly_b[i] = 20;
			holly_year[i]--;
			continue;
		} 
		holly_a[i] = number%13;
		if (holly_a[i] == 0) holly_a[i] = 13;
		holly_b[i] = number%20;
		if (holly_b[i] == 0) holly_b[i] = 20;	
	}
	printf("%d\n", n);
	for (int i = 0; i < n; i++) {
		cout << holly_a[i] << ' ' << holly_word[holly_b[i]] << ' ' << holly_year[i] << endl;
	}
	return 0;
}

 

posted @ 2018-11-16 08:03  JonnyOu1012  阅读(25)  评论(0)    收藏  举报