题意:
玛雅有两种计年方式,输入一种年月日,输出对应的另一种年月日
要点:
1.注意题目要求,第一种还有第19月,一开始没看见,然后输出是一起输出,不是一个一个输出
2.这题主要的一个难点是有关/和%的边界:
例如:26/13=2,26%2=0,如果我想使整除26/13=1,即向下取整,并且想使26%13=13,该怎么办呢?
有个非常好的解决方案就是将要除的数整体-1,也就是原本我们从1开始,现在我们从0开始,这样现在25对应的才是原来的26,25/13=1可以满足我们的需求,这时的26对应原本的27,26/2=2也满足。另外取余时只要整体+1即可,0%13+1=1=1%13,25%13+1=13,满足了我们的需求。
3.A/B的向上取整:(A+B-1)/B
即A整除B时,得到A/B;而不整除时,得到A/B+1,例如:5/3=2,6/2=2,4/3=2,
15099725 | Seasonal | 1008 | Accepted | 216K | 0MS | C++ | 966B | 2016-01-23 18:15:02 |
#include
#include
char month1[19][10] = { "pop", "no", "zip", "zotz",
"tzec", "xul", "yoxkin", "mol",
"chen", "yax", "zac", "ceh", "mac",
"kankin", "muan", "pax", "koyab", "cumhu","uayet" };
char month2[20][10] = { "imix", "ik", "akbal", "kan", "chicchan",
"cimi", "manik", "lamat", "muluk", "ok",
"chuen", "eb", "ben", "ix", "mem",
"cib", "caban", "eznab", "canac","ahau" };
int main()
{
int day, year,month;
int t,num;
int da[5050], yea[5050],mont[5050];
scanf("%d", &t);
num = t;
while (t)
{
char ch[100];
scanf("%d. %s %d", &day, ch, &year);
int i;
for (i = 0; i < 19; i++)
{
if (strcmp(ch, month1[i]) == 0)
break;
}
long data = i * 20+day+year*365; //这里不用+1,天数按0~364来看对下面计算很有利
yea[num-t] = data/ 260;
da[num-t] = data%13+1; //第二种天数没有0的,从1开始到13
mont[num-t] = data % 20;
t--;
}
printf("%d\n", num);
for (int i = 0; i < num; i++)
{
printf("%d %s %d\n", da[i], month2[mont[i]], yea[i]);
}
return 0;
}