码迷,mamicode.com
首页 > 编程语言 > 详细

POJ-1008: Maya Calendar 详解1: 直接计算法

时间:2015-08-09 16:57:15      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

> 分析 

  >> 本题先计算出总天数,再进行转换即可
 
> 注意
  >> 字符串不要抄错
  >> 输出时也要先输出个数
  >> 函数"strnlen"会导致GCC编译不过
 
> 附代码
 1 #include "stdio.h"
 2 #include "stdlib.h"
 3 
 4 const char haabMonStr[19][8] = 
 5 {    "pop", "no", "zip", "zotz", "tzec",
 6     "xul", "yoxkin", "mol", "chen", "yax",
 7     "zac", "ceh", "mac", "kankin", "muan",
 8     "pax", "koyab", "cumhu", "uayet" } ;
 9 
10 const char tzolkinDayStr[20][10] = 
11 {    "imix", "ik", "akbal", "kan", "chicchan", 
12     "cimi", "manik", "lamat", "muluk", "ok", 
13     "chuen", "eb", "ben", "ix", "mem", 
14     "cib", "caban", "eznab", "canac", "ahau" } ;
15 
16 int haabMon2Int(char *mon)
17 {
18     int i = 0 ;
19     
20     for(i = 0; i < 19; i++)
21     {
22         if(memcmp(haabMonStr[i], mon, strlen(mon)) == 0)
23             return i ;
24     }
25 
26     return -1 ;
27 }
28 
29 int main(void)
30 {
31     int n = 0 ;
32     int haabDay = 0 ;
33     char haabMon[8] = {0} ;
34     int haabYear = 0 ;
35     int tzolkinNum = 0 ;
36     int tzolkinDay = 0 ;
37     int tzolkinYear = 0 ;
38     int days = 0 ;
39 
40     scanf("%d", &n) ;
41     printf("%d\r\n", n) ;
42 
43     while(n--)
44     {
45         scanf("%d. %s %d", &haabDay, haabMon, &haabYear) ;
46         
47         days = haabYear * 365 + haabMon2Int(haabMon) * 20 + haabDay ;
48 
49         tzolkinYear = days / 260 ;
50         tzolkinNum = days % 260 % 13 ;
51         tzolkinDay = days % 260 % 20 ;
52 
53         printf("%d %s %d\r\n", tzolkinNum + 1, 
54             tzolkinDayStr[tzolkinDay], tzolkinYear) ;
55     }
56 
57     return 0 ;
58 }

 

POJ-1008: Maya Calendar 详解1: 直接计算法

标签:

原文地址:http://www.cnblogs.com/codesworld/p/4715355.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!