poj1008 模拟

/*题意:将Haab日历转化为Tzolkin日历
Haab日历:一年365天,共19个月,每个月有一个名字,前18个月每月20天,每天编号0-19,最后一个月5天,每天编号0-4
Tzolkin日历:一年260天,共13个阶段,每阶段20天,一年共260天,每一天由(day number,day name)构成(类似天干地支也!),day number编号为1-13。
世界的第一天编号为0(number 0 was the beginning of the world). 

算法:模拟,注意边界值(第1天、第260天....) 

难度:** 

*/

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

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


// 根据Haab日历返回总的天数,从0开始计算 
int getSumDays(int day,char * month,int year)
{
        int m;
        for (m=0; m<20; m++)
        {
                if (strcmp(haap_month[m],month) == 0)
                {
                        break;
                }
        }
        return year * 365 + m * 20 + day; // 世界从0开始 
}


void getTzolkin(int sum_days)
{
        // 0 1 2 ... 259 260 ... 519 520 ...
        // 0 0 0 ... 0   1   ... 1   2
        int year = sum_days / 260;

        // 0 1 2 ... 19 20 21 ...  259 ...
        // 0 1 2 ... 19 0  1  ...  19  ...
        int name = sum_days  % 20 ;

        // 0 1 2 ... 12 13 14 ...
        // 1 2 3 ... 13 1  2  ...
        int number =  sum_days % 13 +1 ;

        printf("%d %s %d\n",number,tzolkin_day_name[name],year); 
}


int main()
{ 
        int day,year;
        char month[10];
        int cases;
        scanf("%d",&cases);
        // 未输出the number of the output dates,n次WA... 
        printf("%d\n",cases); 
        for (int i=0; i<cases; i++)
        {
                scanf("%d. %s %d",&day,&month,&year);
                getTzolkin(getSumDays(day,month,year));
        }
} 


你可能感兴趣的:(模拟)