代码有点长。。不过纯粹是因为不想用C语言字符串的缘故。。。
在自己机子上通过,在POJ上显示Runtime Error,不知为何TAT
#include "stdio.h"
int main(){
long i,j,k,l,n,n1,n2,flag,m,day;
char ch;
int months[259],days[259];
scanf("%d",&n);
printf("%d\n",n);
k=0;l=0;
//Initialize.
for(i=0;i<=259;i++){
months[i]=k+1;
days[i]=l;
k=(k+1)%13;
l=(l+1)%20;
}
for(i=1;i<=n;i++){
n1=n2=flag=0;
//This period is used to read and decompose Haab calendar.
while (1==1){
ch=getchar();
if((ch<30)&&(flag==1))break;
if((ch>=48)&&(ch<=57)){
if(flag)n2=n2*10+ch-48;else n1=n1*10+ch-48;
}
if (ch=='.')ch='.';
if (ch==' ')flag=1;
if (ch>=97){
//This period is used to turn Haab months into numbers.
switch(ch){
case 'p':ch=getchar();
switch(ch){
case 'o':m=0;break;
case 'a':m=15;break;
default:break;
}
break;
case 'n':m=1;break;
case 'z':ch=getchar();
switch(ch){
case 'i':m=2;break;
case 'o':m=3;break;
case 'a':m=10;break;
default:break;
}
break;
case 't':m=4;break;
case 'x':m=5;break;
case 'y':ch=getchar();
switch(ch){
case 'o':m=6;break;
case 'a':m=9;break;
default:break;
}
break;
case 'm':ch=getchar();
switch(ch){
case 'o':m=7;break;
case 'a':m=12;break;
case 'u':m=14;break;
default:break;
}
break;
case 'c':ch=getchar();
switch(ch){
case 'h':m=8;break;
case 'e':m=11;break;
case 'u':m=17;break;
default:break;
}
break;
case 'k':ch=getchar();
switch(ch){
case 'a':m=13;break;
case 'o':m=16;break;
default:break;
}
break;
case 'u':m=18;break;
default:break;
}
while(ch>=97)ch=getchar();
}
}
//This period is used to turn Haab calendar into days.
day=n2*365+m*20+n1;//Start From Day 0.
//This period is used to turn days into T calendar.
n2=day/260;
k=day%260;
m=months[k];
n1=days[k];
//This period is used to print T calendar.
printf("%d ",m);
switch(n1){
case 0:printf("imix ");break;
case 1:printf("ik ");break;
case 2:printf("akbal ");break;
case 3:printf("kan ");break;
case 4:printf("chicchan ");break;
case 5:printf("cimi ");break;
case 6:printf("manik ");break;
case 7:printf("lamat ");break;
case 8:printf("muluk ");break;
case 9:printf("ok ");break;
case 10:printf("chuen ");break;
case 11:printf("eb ");break;
case 12:printf("ben ");break;
case 13:printf("ix ");break;
case 14:printf("mem ");break;
case 15:printf("cib ");break;
case 16:printf("caban ");break;
case 17:printf("eznab ");break;
case 18:printf("canac ");break;
case 19:printf("ahau ");break;
default:break;
}
printf("%d",n2);
if (i!=n)printf("\n");
}
return 0;
//imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau
}