首页 > 其他 > 详细

POJ1008 Maya Calendar

时间:2014-07-18 19:11:30      阅读:371      评论:0      收藏:0      [点我收藏+]

一、题目源程序

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
    const char *Haab[19]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
    const char *Tzolkin[20]={"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac",
                            "ahau"};
    int num;
    int hday,tday;
    int hmonth,tmonth;
    char hname[10],tname[10];
    int hyear,tyear;
    int i,j=0;
    long sum = 0;
    scanf("%d", &num);
    printf("%d\n",num);
    for(i = 0; i<num; i++)
    {
        scanf("%d.%s %d",&hday,&hname,&hyear);
        j=0;
        while(strcmp(hname,Haab[j]) !=0)
            j++;
        hmonth = j;

          sum = hyear * 365 + hmonth * 20 + hday+1;

          tyear = sum / 260;
          tmonth =sum%260;

         if((sum >=259) && ((sum%260) == 0))//此处应该特别注意,最后一天的处理,例如260 这天是0年而不是1年
         {

              tyear-=1;
         }

          if(tmonth % 20 == 0)//处理整除的情况下应该为最后一个数,而不是第一个数
          {
              tmonth = 19;
          }
          else
          {
              tmonth = tmonth%20-1;
          }

          tday = sum%260;
          if(tday % 13 == 0)
              tday =13;
          else
              tday %= 13;
          strcpy(tname,Tzolkin[tmonth]);
          printf("%d %s %d\n",tday,tname,tyear);
        }
    return 0;

}

二、解题思路

1.本题解题思路较为简单。主要是求出总天数。

2.注意一些细节问题

3.日期与对应名字的转换可以通过数组来实现!

三、心得体会

起初,日期与对应名字的转换,我是通过switch选择结构来做的,占用很大篇幅。之后才知道可以用数组做,简单很多,方便很多。

就是在这种不断积累中实现进步的!

POJ1008 Maya Calendar,布布扣,bubuko.com

POJ1008 Maya Calendar

原文:http://www.cnblogs.com/fightfor/p/3850851.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!