POJ1008

 2014-08-22

题意:

  (有中文版题目。。)

   就是两种历法的转换

 

思路:

  把两种历法的细节了解了就很简单了

  Haab历法一年365,Tzolkin一年260天

  先求出总天数sumDay,然后sumDay/260就是Tzolkin历的年份

  T历的天名称20一循环,我们只需建立名称与1-20的关系就行,对20取模即可

  T历的天数字同理可得到

  (注意输入输出格式!)

代码:

  

 1 //Memory Time  

 2 //352K   0MS 

 3 

 4 #include <stdio.h>

 5 

 6 int getHmonth(char *Hmonth){

 7     int i,asciiSum=0;

 8     for(i=0;Hmonth[i];i++){

 9         asciiSum+=Hmonth[i];

10     }

11     //将H历每个月份所含字母的ascii码求和,利用swich语句得到对应第几个月(注意从0开始的)

12     switch(asciiSum)

13     {

14         case 335:

15             return 0;  

16         case 221:

17             return 1;  

18         case 339:

19             return 2;  

20         case 471:

21             return 3;  

22         case 438:

23             return 4;  

24         case 345:

25             return 5; 

26         case 674:

27             return 6;

28         case 328:

29             return 7;

30         case 414:

31             return 8; 

32         case 338:

33             return 9;  

34         case 318:

35             return 10;

36         case 304:

37             return 11;  

38         case 305:

39             return 12; 

40         case 636:

41             return 13;

42         case 433:

43             return 14;

44         case 329:

45             return 15;

46         case 534:

47             return 16;

48         case 546:

49             return 17;

50         case 552:

51             return 18;

52     }

53 }

54 int main()

55 {

56     char Tday[21][10]={"ahau","imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};

57     int i,n;

58     scanf("%d",&n);

59     printf("%d\n",n);

60     int sumDay,Hyear,Hday,hMonthNum;

61     char Hmonth[10];

62     for(i=0;i<n;i++){

63         scanf("%d. %s %d",&Hday,Hmonth,&Hyear);

64         hMonthNum=getHmonth(Hmonth);

65         sumDay=365*Hyear+Hday+hMonthNum*20;

66         printf("%d %s %d\n",sumDay%13+1,Tday[sumDay%20+1],sumDay/260);

67     }

68     return 0;

69 }

 

PS:注意下一些"+1"之类的细节

 

你可能感兴趣的:(poj)