解题思路
1.分别用数组模拟Haab和Tzolkin
2.把给的输入,转化成离世界开始有多少天
3.计算Tzolkin
AC代码
//计算输入的日子离世界开始的天数 days
//年*365 + yue*20 + day
//计算年份 year = days / 260 days -= year*260
// 计算月份 前面的数字num+1 num= days % 13 holly[days%20]
#include<stdio.h>
#include<string.h>
int main(){
char haab[19][10] = {"pop","no","zip","zotz",
"tzec","xul","yoxkin","mol","chen"
,"yax","zac","ceh","mac","kankin"
,"muan","pax","koyab","cumhu","uayet"}; //一年365
char holly[20][10]={"imix", "ik", "akbal", "kan",
"chicchan", "cimi", "manik", "lamat",
"muluk", "ok", "chuen", "eb", "ben", "ix",
"mem", "cib", "caban", "eznab", "canac", "ahau"};//一年260天
int n;
int date,year,days;
char month[10];
scanf("%d",&n);
printf("%d\n",n);
for(int i=0;i<n;i++){
scanf("%d. %s %d",&date,month,&year); //学习了
int count;
for(count=0;count<19;count++) //学习了
if(!strcmp(haab[count],month))
break;
//计算输入的日子离世界开始的天数 days
days = year*365+count*20+date;
//计算Tzolkin
int tyear = days / 260;
days -= tyear*260;
int num = days %13;
int mon = days %20;
printf("%d %s %d\n",num+1,holly[mon],tyear);
}
return 0;
}
总结
1)用数组模拟
2)两个日历的转换,使用中间公共的日子,例如离开始日子多少天
3)格式化输入
scanf("%d. %s %d",&date,month,&year)
4)找字符串出现在第几个
for(count=0;count<19;count++)
if(!strcmp(haab[count],month))
break;