• POJ 1008 Maya Calendar


    很简单的历法转换问题,思路是全部统一成距离0:0:0的总日数,之后再按照格式计算即可。

    有两个需要注意的:

    1、输出的第一行需要是有3的,第一次WA就是因为忽视了这个问题

    2、有一个Special Case:  

    4. uayet 259

    正解是 13 ahau 364
    而不是13 ahau 365

    代码如下:

     1 /* 
     2  * File:   Maya.h
     3  * Author: chrischeng021 <chrischeng021@gmail.com>
     4  *
     5  * Created on July 9, 2015, 4:14 PM
     6  */
     7 
     8 #ifndef MAYA_H
     9 #define    MAYA_H
    10 
    11 int input_num,flag = 0;
    12 
    13 char *Tzolkin_Day_Name[] = {"imix", "ik", "akbal", "kan", "chicchan", "cimi",
    14     "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem",
    15     "cib", "caban", "eznab", "canac", "ahau"};
    16 
    17 char *Haab_Month_Name[] = {"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin",
    18     "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax",
    19     "koyab", "cumhu", "uayet"};
    20 
    21 int calcularDays(char in_day[10],char in_month[5], int in_year){
    22     int days_from_begin = 0;
    23     int day = atoi(in_day);
    24     int cmpRet,i;
    25     days_from_begin += 365 * in_year;
    26     if(flag == 0){
    27         printf("%d
    ",input_num);
    28         flag = -1;
    29     }
    30     for(i = 0; i< 19; i++){
    31         if((cmpRet = strcmp(Haab_Month_Name[i],in_month)) == 0){
    32             days_from_begin += 20 * i;
    33             break;
    34         }
    35         else
    36             continue;
    37     }
    38     days_from_begin += atoi(in_day) + 1;
    39     return days_from_begin;
    40 }
    41 void calcularTzolkinDate(int days_from_begin){
    42     int ret_day;
    43     int ret_ped;
    44     int ret_yer;
    45     int leftDays;
    46     ret_yer = (days_from_begin%260 == 0 ? days_from_begin/260 - 1 : days_from_begin/260);
    47     leftDays = days_from_begin - 260 * ret_yer;
    48     ret_ped = (leftDays%13 == 0 ? 13 : leftDays%13);
    49     ret_day = (leftDays%20 == 0 ? 20 : leftDays%20);
    50     printf("%d %s %d
    ",ret_ped, Tzolkin_Day_Name[ret_day - 1],ret_yer);
    51 }
    52 
    53 void process(){
    54     int  days_from_begin = 0,i;
    55     char in_month[5];
    56     char in_day[10];
    57     int  in_year;
    58     scanf("%d",&input_num);
    59     i = input_num;
    60     while(i-- > 0){
    61         scanf("%s%s%d",in_day, in_month, &in_year);
    62         days_from_begin = calcularDays(in_day, in_month, in_year);
    63         calcularTzolkinDate(days_from_begin);
    64     }
    65 }
    66 
    67 #endif    /* MAYA_H */
  • 相关阅读:
    C/C++中的内存对齐 C/C++中的内存对齐
    Java编程提高性能时需注意的地方
    微软HoloLens技术解谜
    MySQL索引原理及慢查询优化
    mysql 2006
    第9周个人总结
    第十周任务安排
    下一阶段学习安排
    写在软考弃考之后
    第九周任务安排
  • 原文地址:https://www.cnblogs.com/chrischeng/p/4633563.html
Copyright © 2020-2023  润新知