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

题目链接:

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

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

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

AC代码

#include
#include
#include
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;
}

你可能感兴趣的:(POJ)