Problem 300: Maya Calender

Moderator: Board moderators

Problem 300: Maya Calender

I am quiet frustrated !!!!!!! I got Run Time Error but can't find out what the flaw is. I would be very much glad if anyone comes forward to help me in finding that flaw.

my code has been deleted as I got AC
Last edited by Ferdous on Sun Mar 07, 2004 9:42 am, edited 1 time in total.
I am destined to live on this cruel world........
Ferdous
New poster

Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm

I am not quite sure what your runtime error is...but I am quite distressed by the way you havent used the modulus operator(%) instead of subtracting everytime...
ie
z=x-w*y
do z=x%y
Just another brick in the wall...
helmet
New poster

Posts: 31
Joined: Tue Mar 02, 2004 11:55 am

How about leading zero(s) and space(s) before the haab day? There might be cases like these :

0000000000001. pop 0
001. pop 00001
____1. pop 1

('_' means space )

Raiyan Kamal
Experienced poster

Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm

The Haab Months can be given in upper case. So, ignore the case while comparing.
sidky
New poster

Posts: 50
Joined: Wed Nov 06, 2002 1:37 pm
Location: Planet Earth, Universe

Dear Sidky, I dont think there are upper case letters in the input. I did not handle that and my code was AC. By the way, I got same time as you in this.

For Ferdous,
look at your haab months! You have a month named "cumlu" but it should be "cumhu" !!
This mistake is enough to give you a RTE.
Raiyan Kamal
Experienced poster

Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm

I made changes in my code as Raiyan and sidky told. But it has ushered in new horizon of frustration !!!!!! This time it is awarded WA. This kind of situation really makes me averse to problem solving. I just can't understand what to do....... can't find any fault. Please extend to me your helping hands and for that I would be evergrateful.
Last edited by Ferdous on Sun Mar 07, 2004 9:44 am, edited 1 time in total.
I am destined to live on this cruel world........
Ferdous
New poster

Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm

Firstly, I recommend that you take the haab day input as long or unsigned long instead of string.

Secondly, try this : -

Code: Select all
`total = h_year*365 + i*20 + h_day ; // dont add the 1 heret_year = total/260; current = total%260; t_month = current%20; if(!t_month) t_month = 20; t_day = current%13 + 1; // add the 1 here//if(!t_day) t_day = 13;`
Raiyan Kamal
Experienced poster

Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm

Raiyan, I made the following change but this time also it's awarded WA.

scanf("%lu %c %s %lu", &h_day, &a, h_month, &h_year); // a for '.'

scanf("%s %s %lu", a, h_month, &h_year); // a for haab day with '.'

I tried according to your second way of fixing mistake. But it gives wrong answer for 0. pop 0. So I changed my code according to your first way but.....WA. By the way, can anybody tell me whether my algorithm for solving this problem is right?
I am destined to live on this cruel world........
Ferdous
New poster

Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm

You can take the input like this :
Code: Select all
`scanf("%ld. %s %ld",&hd,&hm,&hy);`

hd=haab day;hm=haab month;hy=haab year;
I don't know wheather it'll make any differecnce or not.

This is what I did in the calculation part :
Code: Select all
`d=hy*365 + i*20 + hd;ty=d/260;d=(d-ty*260);td=d%13 + 1;strcpy(tm,tzolkin[d%20]);`

d=total days. total in your code.
ty=tzolkin year
td=tzolkin day( the period )
tm=tzolking name of the day.

The t_month can be 0, no need to make it 20 if it is 0. just print the 0th element from the array. Do same in all other cases, print the nth element , not the (n-1)th.

Raiyan Kamal
Experienced poster

Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm

finally I have received AC . Thank you very very much for your great help.
By the way, I can't understand what difference it makes when I change that portion. Would you please explain it?
I am destined to live on this cruel world........
Ferdous
New poster

Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm

Re: Problem 300: Maya Calender

Who are getting WA
can try this case
Input :
Code: Select all
`219. mac 019. mac 2`

Output :
Code: Select all
`213 ahau 02 ok 3`
@li_kuet
New poster

Posts: 24
Joined: Fri May 25, 2012 6:22 pm

Re: Problem 300: Maya Calender

I had tried many times,but still WA.
My output are same with the AC output.
What's wrong with my code?
(C++)

#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int yy=0,s=0;
char d[500]={0},numss[15]={0},ss[5]={0};
cin.getline(ss,5,'\n');
for(int i=0;ss[i]!='\0';i++)s=s*10+(int)(ss[i]-48);
cout<<s<<endl;
for(int kk=0;kk<s;kk++)
{
yy=0;
memset(d,0,sizeof(d));
memset(numss,0,sizeof(numss));
cin.getline(d,499,'\n');
int lon=1,lon2=1;
for(int i=0;d[i]!=32;i++)lon++;
for(int i=lon;d[i]!=32;i++)
{
numss[i-lon]=d[i];
lon2++;
}
for(int i=lon+lon2;d[i]!='\0';i++)
yy=yy*10+(int)(d[i]-48);
int day=(int)(d[lon-3]-48)+(int)((lon-3)==0?0:10*(d[lon-4]-48))+1;
int all=0;
char haab[19][10]={"pop","no","zip","zotz","tzec","xul",
"yoxkin","mol","chen","yax","zac",
"ceh","mac","kankin","muan","pax",
"koyab","cumhu","uayet"};
for(int i=0;i<19;i++)
{
bool gain=false;
for(int j=0;numss[j]!='\0';j++)
{
if(numss[j]==haab[i][j])
{
if(numss[j+1]=='\0')
{
all=(365*yy)+day+(i*20);
gain=true;
}
}
else break;
}
if(gain)break;
}
int month;
if(!(all%260))
{
yy=(all/260)-1;
month=13;
cout<<month<<" ahau "<<yy<<endl;
}
else
{
yy=all/260;
month=all%13;
int tem=all%20;
char lkk[20][10]={"ahau","imix","ik","akbal","kan","chicchan",
"cimi","manik","lamat","muluk","ok","chuen",
"eb","ben","ix","mem","cib","caban","eznab","canac"};
cout<<month<<' '<<lkk[tem]<<' '<<yy<<endl;
}
}
return 0;
}
ta89011
New poster

Posts: 1
Joined: Sat Dec 08, 2012 3:43 am

Re: Problem 300: Maya Calender

Try changing your input parsing to handle an input with spaces inserted at different places.
Code: Select all
`21. pop 1 1. pop 1`
brianfry713
Guru

Posts: 1765
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA