Problem:
During his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya calendar. From an old knotted message, professor discovered that the Maya civilization used a 365 day long year, called Haab, which had 19 months. Each of the first 18 months was 20 days long, and the names of the months were pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu. Instead of having names, the days of the months were denoted by numbers starting from 0 to 19. The last month of Haab was called uayet and had 5 days denoted by numbers 0, 1, 2, 3, 4. The Maya believed that this month was unlucky, the court of justice was not in session, the trade stopped, people did not even sweep the floor.
For religious purposes, the Maya used another calendar in which the year was called Tzolkin (holly year). The year was divided into thirteen periods, each 20 days long. Each day was denoted by a pair consisting of a number and the name of the day. They used 20 names: imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau and 13 numbers; both in cycles.
Notice that each day has an unambiguous description. For example, at the beginning of the year the days were described as follows:
1 imix, 2 ik, 3 akbal, 4 kan, 5 chicchan, 6 cimi, 7 manik, 8 lamat, 9 muluk, 10 ok, 11 chuen, 12 eb, 13 ben, 1 ix, 2 mem, 3 cib, 4 caban, 5 eznab, 6 canac, 7 ahau, and again in the next period 8 imix, 9 ik, 10 akbal . . .
Years (both Haab and Tzolkin) were denoted by numbers 0, 1, : : : , where the number 0 was the beginning of the world. Thus, the first day was:
Haab: 0. pop 0
Tzolkin: 1 imix 0
Help professor M. A. Ya and write a program for him to convert the dates from the Haab calendar to the Tzolkin calendar.
Input
The date in Haab is given in the following format:
NumberOfTheDay. Month Year
- The first line of the input file contains the number of the input
dates in the file. The next n lines contain n dates in the Haab
calendar format, each in separate line. The year is smaller then
5000.
Output
The date in Tzolkin should be in the following format:
Number NameOfTheDay Year
- The first line of the output file contains the number of the output
dates. In the next n lines, there are dates in the Tzolkin calendar
format, in the order corresponding to the input dates.
Sample Input
3
10. zac 0
0. pop 0
10. zac 1995
Sample Output
3
3 chuen 0
1 imix 0
9 cimi 2801
所有的日历问题都要注意一个事:
假设一年有260天,年份从0开始,第0年,第1年,……
252/260=0,所以在第0年;260/260=1,但这一天仍然是属于第0年的,所以这个时候一定要减一年。
代码如下:纯C的,有点繁琐,见谅
#include<stdio.h>
#include<string.h>
int Haab(void){
char hms[8];
int hm,hd,hy,num;
scanf("%d. %s %d",&hd,hms,&hy);
if(!strcmp(hms,"pop")) hm = 0;
else if(!strcmp(hms,"no")) hm = 1;
else if(!strcmp(hms,"zip")) hm = 2;
else if(!strcmp(hms,"zotz")) hm = 3;
else if(!strcmp(hms,"tzec")) hm = 4;
else if(!strcmp(hms,"xul")) hm = 5;
else if(!strcmp(hms,"yoxkin")) hm = 6;
else if(!strcmp(hms,"mol")) hm = 7;
else if(!strcmp(hms,"chen")) hm = 8;
else if(!strcmp(hms,"yax")) hm = 9;
else if(!strcmp(hms,"zac")) hm = 10;
else if(!strcmp(hms,"ceh")) hm = 11;
else if(!strcmp(hms,"mac")) hm = 12;
else if(!strcmp(hms,"kankin")) hm = 13;
else if(!strcmp(hms,"muan")) hm = 14;
else if(!strcmp(hms,"pax")) hm = 15;
else if(!strcmp(hms,"koyab")) hm = 16;
else if(!strcmp(hms,"cumhu")) hm = 17;
else if(!strcmp(hms,"uayet")) hm = 18;
num = hy * 365 + hm * 20 + hd + 1;
//printf("num=%d\n",num);
return num;
}
void Tzolkin(int num){
int tm,ty,td,tmp;
char tds[8];
ty = num / 260;
tmp = num - ty * 260;
if(tmp == 0) ty--;
td = tmp % 20;
tm = tmp % 13;
if(tm == 0){
tm = 13;
}
switch(td){
case 0:strcpy(tds,"ahau");break;
case 1:strcpy(tds,"imix");break;
case 2:strcpy(tds,"ik");break;
case 3:strcpy(tds,"akbal");break;
case 4:strcpy(tds,"kan");break;
case 5:strcpy(tds,"chicchan");break;
case 6:strcpy(tds,"cimi");break;
case 7:strcpy(tds,"manik");break;
case 8:strcpy(tds,"lamat");break;
case 9:strcpy(tds,"muluk");break;
case 10:strcpy(tds,"ok");break;
case 11:strcpy(tds,"chuen");break;
case 12:strcpy(tds,"eb");break;
case 13:strcpy(tds,"ben");break;
case 14:strcpy(tds,"ix");break;
case 15:strcpy(tds,"mem");break;
case 16:strcpy(tds,"cib");break;
case 17:strcpy(tds,"caban");break;
case 18:strcpy(tds,"eznab");break;
case 19:strcpy(tds,"canac");break;
default:break;
}
printf("%d %s %d\n",tm,tds,ty);
}
int main(void){
int n,nn,num;
scanf("%d",&n);
printf("%d\n",n);
nn = n;
while(nn--){
num = Haab();
Tzolkin(num);
}
return 0;
}