这是一道关于历法转换的问题。从这道题我得到2点收获:一、题目中月份或者日期是用字符串来表示的,这时利用二位数组可以轻松实现从字符串到数字的转换;二、Tzolkin中的日期和月数是相互独立的,可分别取余。
另外,我觉得很重要的一点就是,一定要清楚题目是从0,还是从1开始数的,并且在取余时候关于这方面一定要保持头脑清醒。很容易出错。
1 #include<stdio.h>
2 #include<string.h>
3 #include<stdlib.h>
4 int n;
5 char haabmonth[19][10] = {"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
6 char tzolkinday[20][10] = {"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
7 int day;
8 char month[10];
9 int year;
10 int main()
11 {
12 scanf("%d",&n);
13 printf("%d\n",n);
14 for(int i = 0;i < n;++i){
15 scanf("%d. %s %d",&day,month,&year);
16 int days;
17 for(int k = 0;k < 19;++k){
18 if(!strcmp(haabmonth[k],month)){
19 days = year * 365 + k * 20 + day;
20 break;
21 }
22 }
23 int m = days % 260;
24 printf("%d %s %d\n",m%13+1,tzolkinday[m%20],days/260);
25 }
26 system("pause");
27 return 0;
28 }
29
code