Problem 300: Maya Calender

All about problems in Volume III. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Problem 300: Maya Calender

Postby Ferdous » Wed Feb 25, 2004 10:18 am

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
Location: Dhaka, Bangladesh

Postby helmet » Thu Mar 04, 2004 1:02 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
instead of w=x/y
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

Postby Raiyan Kamal » Thu Mar 04, 2004 8:32 pm

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 )

Hope this will help you.
Raiyan Kamal
Experienced poster
 
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh

Postby sidky » Fri Mar 05, 2004 5:41 am

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

Postby Raiyan Kamal » Fri Mar 05, 2004 10:16 am

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" !! :wink:
This mistake is enough to give you a RTE.
Raiyan Kamal
Experienced poster
 
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh

Postby Ferdous » Fri Mar 05, 2004 2:39 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
Location: Dhaka, Bangladesh

Postby Raiyan Kamal » Fri Mar 05, 2004 5:04 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 here

t_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
Location: Bangladesh

Postby Ferdous » Sun Mar 07, 2004 8:08 am

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 '.'

instead of

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
Location: Dhaka, Bangladesh

Postby Raiyan Kamal » Sun Mar 07, 2004 9:01 am

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.

If you still get WA, then give me your email address and before doing that, make sure that there is no spelling mistakes in your tzolkin months and also chek their ordering.
Raiyan Kamal
Experienced poster
 
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh

Postby Ferdous » Sun Mar 07, 2004 9:22 am

finally I have received AC :lol: . 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
Location: Dhaka, Bangladesh

Re: Problem 300: Maya Calender

Postby @li_kuet » Sat Aug 18, 2012 8:48 pm

Who are getting WA :(
can try this case
Input :
Code: Select all
2
19. mac 0
19. mac 2

Output :
Code: Select all
2
13 ahau 0
2 ok 3
@li_kuet
New poster
 
Posts: 24
Joined: Fri May 25, 2012 6:22 pm
Location: Chittagong, Bangladesh

Re: Problem 300: Maya Calender

Postby ta89011 » Sat Dec 08, 2012 3:52 am

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

Postby brianfry713 » Tue Dec 11, 2012 1:19 am

Try changing your input parsing to handle an input with spaces inserted at different places.
Code: Select all
2
1. pop 1
 1. pop 1
brianfry713
Guru
 
Posts: 1765
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA


Return to Volume III

Who is online

Users browsing this forum: No registered users and 1 guest