POJ1008

本文深入探讨了两种日历系统间的转换算法,重点讲解了在特定条件下,如何处理holly日历的最后一天计算问题。通过分析日期构成,将年、月、日转换为对应的holly日历表示,涉及字符串操作、数学计算及条件判断。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

理解题意之后很容易得到两个日历之间的换算,但是要注意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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值