北大ACM训练题(1008——Maya Calendar)

题目链接:

先求出给出的日期从世界开始是第几天,再转换为holly日历就行了,注意天数能被260整除的情况,是上一年的最后最后一天,不是新的一年的第一天,因为haab日历是从0~19,所以注意转换的时候日期还要加1,为了避免麻烦的判断,haab历从数组0元素开始储存,holly日历也从0开始存,这样就不用再去判断是月初第一天还是月末最后一天。

然后巨坑的是!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

输出例子的数目的时候要把这个数打印出来,wa了一晚上!!!!!!!!!!!!!!!!!!!!!!!!!!

AC代码

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    int i;
    int year;
    char Haab[19][10]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen",
	               "yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
    char holly[20][10]={"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk",
	                "ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
    char month[10];
    int day;
    int d;
    int n;
    scanf("%d",&n);
    printf("%d\n",n);
    while(n--){
    	scanf("%d. %s %d",&d,&month,&year);
    	for(i=0;i<19;i++){
    		if(strcmp(Haab[i],month)==0){
    			break;
    		}
    	}
    	day=year*365+d+20*i;
    	printf("%d %s %d\n",day%13+1,holly[day%20],day/260);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值