ACM题库~ACM-ICPCACM

POJ-1008-Maya Calendar

2017-09-28  本文已影响4人  rock4you

POJ-1008-Maya Calendar
http://poj.org/problem?id=1008

这道题主要涉及到求模运算和字符串数组。
需要考虑的细节是,求模的结果是否能够取0或者最大值。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main()
{
    int i, j, n, num, day;
    scanf("%d", &n);
    char *Haab[19]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
    char *tzol[20]={"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
    char month[10];
    char tmp;
    int year, m, total, tzoyear, tzomonth, tzoday;
    printf("%d\n", n);
    for(i=0;i<n;i++)
    {
        scanf("%d %c %s %d", &num, &tmp, month, &year);
        for(j=0;j<19;j++)
        {
            if(!strcmp(month, Haab[j]))
            {
                m=j;
                j=19;
            }
        }
        total=year*365+m*20+num;
        tzoyear=total/260;
        tzoday=total%260;
        tzomonth=tzoday%20;
        tzoday=tzoday%13+1;
        printf("%d %s %d\n", tzoday, tzol[tzomonth], tzoyear);
    }
    return 0;
}

上一篇下一篇

猜你喜欢

热点阅读