POJ 1008.Maya Calendar

本文介绍了一个基于玛雅历法的日期转换程序。该程序接收公历日期输入,并将其转换为玛雅长计历对应的日名、日数及年数。通过对不同月份的天数累加和年份的特殊处理,实现了从公历到玛雅历的准确转换。

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

类似于之前团队天梯赛碰到的进制转化问题??大概就是到了多少就转化一下

这道题特别需要注意的是 如果刚好能整数,年份要-1,因为没有下一年了

题目链接

(应该是不用改成统一输出的)

#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <cmath>
#include <cstdlib>
/*
8
12.pop 123
13.pop 234
14.pop 456
15.pop 567
16.pop 678
17.pop 789
18.pop 890
19.pop 111
*/
/*
19
1.pop 111
2.no 222
3.zip 333
4.zotz 444
5.tzec 555
6.xul 666
7.yoxkin 777
8.mol 888
9.chen 999
10.yax 1010
8.zac 1111
7.ceh 1212
4.mac 1313
3.kankin 1414
8.muan 1515
13.pax 1616
2.koyab 1717
18.cumhu 1818
0.uayet 1919
*/
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main(int argc, char** argv) {
	int n;
	scanf("%d",&n);
//	printf("%d\n",n); 
	int a[5005];
	char b[5005][50];
	int c[5005];
	for(int p=0;p<n;p++)
	{
		//pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu,uayet
		int day; 
		char s[105];
		int year;
		scanf("%d.%s%d",&day,s,&year);//天 月 年	
//		printf("***%d\t%s\t%d\n",day,s,year); 
		int  total = 0; 
//		total = day +  month* 20 +year*365; 抽象转化为有多少天 
		if(strcmp(s,"pop")==0)//日期转换 
		{
			total = day+1 +  (1-1)*20 +year*365;
		}
		if(strcmp(s,"no")==0)
		{
			total = day+1 + (2-1)*20 + year*365; 
		}
		if(strcmp(s,"zip")==0)
		{
			total = day+1 + (3-1)*20 + year*365; 
		} 
		if(strcmp(s,"zotz")==0)
		{
			total = day+1 + (4-1)*20 + year*365; 
		} 
		if(strcmp(s,"tzec")==0)
		{
			total = day+1 + (5-1)*20 + year*365; 
		} 
		if(strcmp(s,"xul")==0)
		{
			total = day+1 + (6-1)*20 + year*365; 
		} 
		if(strcmp(s,"yoxkin")==0)
		{
			total = day+1 + (7-1)*20 + year*365; 
		} 
		if(strcmp(s,"mol")==0)
		{
			total = day+1 + (8-1)*20 + year*365; 
		} 
		if(strcmp(s,"chen")==0)
		{
			total = day+1 + (9-1)*20 + year*365; 
		} 
		if(strcmp(s,"yax")==0)
		{
			total = day+1 + (10-1)*20 + year*365; 
		} 
		if(strcmp(s,"zac")==0)
		{
			total = day+1 + (11-1)*20 + year*365; 
		} 
		if(strcmp(s,"ceh")==0)
		{
			total = day+1 + (12-1)*20 + year*365; 
		} 
		if(strcmp(s,"mac")==0)
		{
			total = day+1 + (13-1)*20 + year*365; 
		} 
		if(strcmp(s,"kankin")==0)
		{
			total = day+1 + (14-1)*20 + year*365; 
		} 
		if(strcmp(s,"muan")==0)
		{
			total = day+1 + (15-1)*20 + year*365; 
		} 
		if(strcmp(s,"pax")==0)
		{
			total = day+1 + (16-1)*20 + year*365; 
		} 
		if(strcmp(s,"koyab")==0)
		{
			total = day+1 + (17-1)*20 + year*365; 
		}  
		if(strcmp(s,"cumhu")==0)
		{
			total = day+1 + (18-1)*20 + year*365; 
		} 
		if(strcmp(s,"uayet")==0)
		{
			total = day+1 + (19-1)*20 + year*365; 
		} 
//		if(strcmp(s,"zac")==0)
//		{
//			total = day+1 + (11-1)*20 + year*365;
//		}
	//total记录下了有多少天
		
		int yearr = total/260;
		if(total%260==0)
		yearr --;//能整除260的话要减一。。。。 没有到下一年 
		total %=260; // 
	//	printf("%d ",yearr);
		int month = total%13; 
		total %= 20; //现在剩余的就是day了 
//		total%=20;
	//	printf("%d ",month);	
	//	printf("%d\n",total);
		if(month!=0)
		{
		//	printf("%d ",month);//imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau
			a[p] = month;
		}
		else
		{
		//	printf("13 ");
			a[p] = 13;
		}
		// printf("%s ")	 暂时抽象
		if(total==1)
		{
		//	printf("imix "); 
			strcpy(b[p],"imix");
		}
		if(total==2)
		{
		//	printf("ik ");
			strcpy(b[p],"ik");
		}
		if(total==3)
		{
		//	printf("akbal ");
			strcpy(b[p],"akbal");
		}
		if(total==4)	
		{
	//	printf("kan ");
		strcpy(b[p],"kan");
		}	
		if(total==5)
		{
		//	printf("chicchan ");
			strcpy(b[p],"chicchan");
		}
		if(total==6)
		{
		//	printf("cimi ");
			strcpy(b[p],"cimi");
		}
		if(total==7)
		{	
		//	printf("manik ");
			strcpy(b[p],"manik");
		}
		if(total==8){
		//	printf("lamat ");
			strcpy(b[p],"lamat");
		}
		if(total==9){
		//	printf("muluk ");
			strcpy(b[p],"muluk");
		}
		if(total==10){
		//	printf("ok ");
			strcpy(b[p],"ok");
		}
		if(total==11){
		//	printf("chuen ");
			strcpy(b[p],"chuen");}
		if(total==12){//	printf("eb ");
		strcpy(b[p],"eb");}
		if(total==13){//	printf("ben ");
		strcpy(b[p],"ben");}
		if(total==14){//	printf("ix ");
		strcpy(b[p],"ix");}
		if(total==15){//	printf("mem ");
		strcpy(b[p],"mem");}
		if(total==16){//	printf("cib ");
		strcpy(b[p],"cib");}
		if(total==17){//	printf("caban ");
		strcpy(b[p],"caban");}
		if(total==18){//printf("eznab ");
		strcpy(b[p],"eznab");}
		if(total==19){	//printf("canac ");
		strcpy(b[p],"canac");}
		if(total==0){	
		//printf("ahau ");
		strcpy(b[p],"ahau");}
		
		
	//	printf("%d\n",yearr); 
		c[p] = yearr;
	}
	printf("%d\n",n);
	for(int i=0;i<n;i++)
	{
		printf("%d %s %d\n",a[i],b[i],c[i]);	
	} 
	//需要改成统一输出 
	//system("pause");
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值