POJ 2965 玛雅历 解题报告

POJ 2965 玛雅历 解题报告

编号:2965

 

考查点:日期和时间处理

 

思路:在进行进制转换问题,包括日期和时间转换、数制转换的时候,一般需要先找到两种转换之间的公共点,这题里面就是逝去的天数,然后把天数按目的日历显示即可..

 

提交情况: 经过昨天POJ 2964的失败教训,我这次先整理出思路,然后写出框架函数,思路相当清晰,自己debug时因为天数变量未初始化出了点问题,不过只提交一次就直接AC..享受..

 

Source Code


// POJ Grids 2965
#include  < string .h >
#include 
< iostream >
using   namespace  std;

char  Haab[ 19 ][ 10 =  { " pop " , " no " " zip " " zotz " " tzec " " xul " " yoxkin " " mol " " chen " " yax " " zac " " ceh " , " mac " " kankin " " muan " " pax " " koyab " " cumhu " , " uayet " };
char  Tzolkin[ 20 ][ 10 =  { " imix " " ik " " akbal " " kan " " chicchan " " cimi " " manik " " lamat " " muluk " " ok " " chuen " " eb " " ben " " ix " " mem " " cib " " caban " " eznab " " canac " " ahau " };
int  type[ 13 =  { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 };

int  days  =   0 ;

void  calday( char *  day);
void  calmonth( char *  month);
void  calyear( int  year);

int  main()
{
    
int  n;
    cin
>> n;
    cout
<< n << endl;
    
while  (n -- )
    {
        days 
=   0 ;
        
char  day[ 10 ],month[ 10 ];
        
int  year;
        memset(day,
0 , 10 );
        memset(month,
0 , 10 );
        cin
>> day >> month >> year;
        calday(day);
        calmonth(month);
        calyear(year);

        year 
=  days / 260 ;
        days 
%=   260 ;
        cout
<< type[days % 13 ];
        cout
<< "   " ;
        cout
<< Tzolkin[days % 20 ];
        cout
<< "   " ;
        cout
<< year << endl;
    }

    
return   0 ;

}

void  calday( char *  day)
{
    
int  temp  =   * day - ' 0 ' ;
    
while  ( * ( ++ day) != ' . ' )
    {
        temp 
=  temp * 10 +* day - ' 0 ' ;
    }

    days 
+=  temp;
}
void  calmonth( char *  month)
{
    
for  ( int  i = 0 ;i < 19 ;i ++ )
    {
        
if  (strcmp(month,Haab[i]) == 0 )
        {
            days 
+=  i * 20 ;
            
return ;
        }
    }
}
void  calyear( int  year)
{
    days 
+=  year * 365 ;
}

 

总结:循环里用于每次统计的变量,尤其是全局变量,一定要记得每次循环先初始化,然后就是解决日期、时间转换问题要找出两种进制之间的公共点.

 

 

 

                                                       By   Ns517

                                                      Time 09.01.24

转载于:https://www.cnblogs.com/ns517/archive/2009/01/24/1380692.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值