poj1008日历转换

这个题目就是要注意第一种日历的最后一个月,这个要考虑好久基本上可以过了,刚开始看题目的知道但是后来就忘了,所以还是得做一下笔记,这个是经验啊

然后还要注意第二种日历,那三个时期并不是月份,天数和时期数是不相关的,所以要分别考虑而不是一起做

解题思路:
1 先将输入的日期转换为总天数
   sum = year*365+month*20+天数 
2 根据sum求出Tzolkin日历格式的日历
  ansyear = sum/260;
  sum= sum%260;
  ansmonth=sum%13+1; (加1是因为数字从1开始,但不是真正意义上的month)
  ansday=sum%20;

#include<stdio.h>
#include<string.h>


char tag[22][10]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
char tagday[22][10]={"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};


int findmonth(char a[])
{
    for(int i=0;i<20;i++){
        if(!strcmp(a,tag[i]))
            return i;
    }
}


int main()
{
    int T;
    scanf("%d",&T);
    printf("%d\n",T);
    while(T--)
    {
        char month[10];
        int day,year;
        char tem;
        scanf("%d%c%s%d",&day,&tem,month,&year);


        int temp=findmonth(month);
        int sum=year*365+temp*20+day;


        int ansyear,ansmonth;
        char ansday[10];


        ansyear=sum/260;
        sum=sum%260;
        ansmonth=sum%13+1;
        sum=sum%20;


        printf("%d %s %d\n",ansmonth,tagday[sum],ansyear);
    }


    return 0;
}

 
 


你可能感兴趣的:(poj1008日历转换)