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