300 - Maya Calendar

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

Moderator: Board moderators

C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

300 - Maya Calendar

Post by C8H10N4O2 » Sun Apr 28, 2002 4:12 pm

This works for all my test cases. Anyone know of any special tricks to this problem?
[cpp]#include <cstdio>
#include <cstring>

int ResolveMonth (char P[100])
{
char X[19][10]={"pop","no","zip","zotz","tzec","xul",
"yoxkin","mol","chen","yax","zac","ceh",
"mac","kankin","muan","pax","koyab","cumhu",
"uayet"};
int i;

for(i=0;i<19;i++)
{
if(strcmp(P,X)==0)
return i;
}
return -1;
}

void main()
{
int i,j,k,N,n,d,y;
char M[100];
char X[20][10]={"imix","ik","akbal","kan","chicchan",
"cimi","manik","lamat","muluk","ok",
"chuen","eb","ben","ix","mem","cib",
"caban","eznab","canac","ahau"};

scanf("%d",&N);

for(n=0;n<N;n++)
{
scanf("%d.%s%d",&d,&M,&y);
d+=ResolveMonth(M)*20+y*365;
y=d/260;
d%=260;
strcpy(M,X[d%20]);
d%=13;
d++;
printf("%d %s %d\n",d,M,y);
}
}[/cpp]

wyvmak
Experienced poster
Posts: 110
Joined: Thu Dec 13, 2001 2:00 am

Post by wyvmak » Mon Apr 29, 2002 2:11 am

oh, after a few minutes of inspection, you need to add this line after "scanf("%d",&N);":

printf("%d\n",N);

C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 » Mon Apr 29, 2002 12:28 pm

Ah ha! Thank you. Sometimes the simplest details can get you:)

dabendan
New poster
Posts: 13
Joined: Mon May 06, 2002 4:05 pm
Location: ROC

300

Post by dabendan » Tue May 28, 2002 9:27 pm

I got wrong answer.
I can't find the wrong.

[c]#include <stdio.h>
#include <string.h>

long int mon,day,year;
long now;

int main()
{
char b[20][10]={"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
int n;
int index;
void Input();
scanf("%d",&n);
printf("%d\n",n);
for(index=0;index<n;index++){
Input();
now=year*365+mon*20+day;
printf("%ld %s %ld\n",now%13+1,b[now%20],now/260);
}
return(0);
}

void Input()
{
char a[19][10]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
char str[10];
int index;
scanf("%ld. %s %ld",&day,str,&year);
for(index=0;index<19;index++)
{
if(strcmp(str,a[index])==0)
{
mon=index;
break;
}
}
}[/c]

cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland

Hi!

Post by cyfra » Wed May 29, 2002 4:49 pm

Hmm...

There is nothing wrong..

I got your program Accepted without any changes...

Try to change your e-mail client (I use Bat)

Good Luck :wink:

dabendan
New poster
Posts: 13
Joined: Mon May 06, 2002 4:05 pm
Location: ROC

?!

Post by dabendan » Wed May 29, 2002 6:41 pm

That's strange.
I copied my code from here and sent it then I got accept.
But when I sent it from my file then I got wrong answer.
I couldn't find any differences. :roll:

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann » Thu May 30, 2002 12:40 am

Compare the "we got your program" automatic response emails you got back from the judge. They should contain the program as the judge got it.

Do they differ?

Note that I actually expect an answer, just like the dozen times before when I asked this question and nobody ever was kind enough to answer.

dabendan
New poster
Posts: 13
Joined: Mon May 06, 2002 4:05 pm
Location: ROC

Post by dabendan » Thu May 30, 2002 7:29 am

When I copied my codes from file to Outlook Express 5.
It cut my code like that:
[c]#include <stdio.h>
#include <string.h>

long int mon,day,year;
long now;

int main()
{
char
b[20][10]={"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","mulu
k","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
int n;
int index;
void Input();
scanf("%d",&n);
printf("%d\n",n);
for(index=0;index<n;index++){
Input();
now=year*365+mon*20+day;
printf("%ld %s %ld\n",now%13+1,b[now%20],now/260);
}
return(0);
}

void Input()
{
char
a[19][10]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax",
"zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
char str[10];
int index;
scanf("%ld. %s %ld",&day,str,&year);
for(index=0;index<19;index++)
{
if(strcmp(str,a[index])==0)
{
mon=index;
break;
}
}
}[/c]

cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland

Post by cyfra » Thu Jun 20, 2002 3:35 pm

Yes this is the problem in Outlook...

It cuts lines in many places (you can propably change it in options)
and in the middle of your string there is a sign and you get W.A.
but on your place I would check twice before sending if some lines are cut (or change mail client :) ..

Good Luck :wink:

gracia
New poster
Posts: 5
Joined: Mon Nov 25, 2002 9:04 am
Location: jakarta

300-RE

Post by gracia » Fri Jan 03, 2003 11:05 am

can you tell me why i've got runtime error: invalid memory reference
plzzzzz....

User avatar
ezra
New poster
Posts: 31
Joined: Thu Nov 21, 2002 2:11 pm

Post by ezra » Sat May 10, 2003 7:20 am

try to large your array , good luck!

User avatar
szymcio2001
New poster
Posts: 38
Joined: Mon Dec 09, 2002 1:53 pm
Location: Poznan, Poland

Post by szymcio2001 » Sun May 11, 2003 11:49 am

I had RE because I forgot to copy the name of the last month "uayet" to the const array in a source code. The name of it is written few lines below other names in the problem description and this was the cause of my mistake. Maybe you have the similar error.
Good luck!
Szymcio

reza ali
New poster
Posts: 6
Joined: Mon Jun 09, 2003 12:31 am

WA 300

Post by reza ali » Thu Jun 19, 2003 8:12 pm

I think my program is write. Please anybody, check my code.If there is important input you have, send it. Below the code://@begin_of_source_code

#include<iostream.h>
#include<string.h>

int main()
{
/*@JUDGE_ID: ----------- 300 C++ "Dynamic programming" */
unsigned long total;
int n,count,day,year,i,tmonth,dayname,tyear;
char dot,month[10],haab[19][10],tzolkin[20][10];

strcpy(haab[0],"pop");
strcpy(haab[1],"no");
strcpy(haab[2],"zip");
strcpy(haab[3],"zotz");
strcpy(haab[4],"tzec");
strcpy(haab[5],"xul");
strcpy(haab[6],"yoxkin");
strcpy(haab[7],"mol");
strcpy(haab[8],"chen");
strcpy(haab[9],"yax");
strcpy(haab[10],"zac");
strcpy(haab[11],"ceh");
strcpy(haab[12],"mac");
strcpy(haab[13],"kankin");
strcpy(haab[14],"muan");
strcpy(haab[15],"pax");
strcpy(haab[16],"koyab");
strcpy(haab[17],"cumhu");
strcpy(haab[18],"uayet");


strcpy(tzolkin[0],"imix");
strcpy(tzolkin[1],"ik");
strcpy(tzolkin[2],"akbal");
strcpy(tzolkin[3],"kan");
strcpy(tzolkin[4],"chicchan");
strcpy(tzolkin[5],"cimi");
strcpy(tzolkin[6],"manik");
strcpy(tzolkin[7],"lamat");
strcpy(tzolkin[8],"muluk");
strcpy(tzolkin[9],"ok");
strcpy(tzolkin[10],"chuen");
strcpy(tzolkin[11],"eb");
strcpy(tzolkin[12],"ben");
strcpy(tzolkin[13],"ix");
strcpy(tzolkin[14],"mem");
strcpy(tzolkin[15],"cib");
strcpy(tzolkin[16],"caban");
strcpy(tzolkin[17],"eznab");
strcpy(tzolkin[18],"canac");
strcpy(tzolkin[19],"ahau");


while(cin>>n)
{
if (n==0) break;
cout<<n<<endl;
count=0;
while(count++<n)
{
cin>>day>>dot>>month>>year;

if(year>=5000) {cout<<"out of limit";break;}
if(day>19) {cout<<"out of limit";break;}
if(strcmp(month,"uayet")==0) { if(day>4) {cout<<"out of limit";break;}}

for(i=0;i<=18;i++)
{
if(strcmp(month,haab)==0)
{
total=(unsigned long) day+1+(unsigned long)i*20+365*(unsigned long)year;
break;

}
}
if(total>259) tyear=(total/260);
else tyear=0;
total=total%260;
tmonth=total%13; if(tmonth==0) tmonth=13;
dayname=total%20; if(dayname==0) dayname=20;
cout<<tmonth<<" "<<tzolkin[dayname-1]<<" "<<tyear<<endl;

}
}
return 0;
}
//@end_of_source_code

Pupirev Sergei
New poster
Posts: 24
Joined: Mon Feb 24, 2003 5:08 pm

Post by Pupirev Sergei » Fri Jun 20, 2003 8:15 pm

Your counting of tmonth and dayname are wrong!
This code got AC:))

#include<iostream.h>
#include<string.h>

int main()
{
/*@JUDGE_ID: ----------- 300 C++ "Dynamic programming" */
unsigned long total;
int n,count,day,year,i,tmonth,dayname,tyear;
char dot,month[10],haab[19][10],tzolkin[20][10];

strcpy(haab[0],"pop");
strcpy(haab[1],"no");
strcpy(haab[2],"zip");
strcpy(haab[3],"zotz");
strcpy(haab[4],"tzec");
strcpy(haab[5],"xul");
strcpy(haab[6],"yoxkin");
strcpy(haab[7],"mol");
strcpy(haab[8],"chen");
strcpy(haab[9],"yax");
strcpy(haab[10],"zac");
strcpy(haab[11],"ceh");
strcpy(haab[12],"mac");
strcpy(haab[13],"kankin");
strcpy(haab[14],"muan");
strcpy(haab[15],"pax");
strcpy(haab[16],"koyab");
strcpy(haab[17],"cumhu");
strcpy(haab[18],"uayet");


strcpy(tzolkin[0],"imix");
strcpy(tzolkin[1],"ik");
strcpy(tzolkin[2],"akbal");
strcpy(tzolkin[3],"kan");
strcpy(tzolkin[4],"chicchan");
strcpy(tzolkin[5],"cimi");
strcpy(tzolkin[6],"manik");
strcpy(tzolkin[7],"lamat");
strcpy(tzolkin[8],"muluk");
strcpy(tzolkin[9],"ok");
strcpy(tzolkin[10],"chuen");
strcpy(tzolkin[11],"eb");
strcpy(tzolkin[12],"ben");
strcpy(tzolkin[13],"ix");
strcpy(tzolkin[14],"mem");
strcpy(tzolkin[15],"cib");
strcpy(tzolkin[16],"caban");
strcpy(tzolkin[17],"eznab");
strcpy(tzolkin[18],"canac");
strcpy(tzolkin[19],"ahau");


while(cin>>n)
{
if (n==0) break;
cout<<n<<endl;
count=0;
while(count++<n)
{
cin>>day>>dot>>month>>year;

if(year>5000) {cout<<"out of limit";break;}
if(day>19) {cout<<"out of limit";break;}
if(strcmp(month,"uayet")==0) { if(day>4) {cout<<"out of limit";break;}}

for(i=0;i<=18;i++)
{
if(strcmp(month,haab)==0)
{
total=(unsigned long) day+(unsigned long)i*20+365*(unsigned long)year;
break;

}
}
if(total>259) tyear=(total/260);
//else tyear=0;
total=total%260;
tmonth=total%13+1; //if(tmonth==0) tmonth=13;
dayname=total%20; //if(dayname==0) dayname=20;
cout<<tmonth<<" "<<tzolkin[dayname]<<" "<<tyear<<endl;

}
}
return 0;
}

reza ali
New poster
Posts: 6
Joined: Mon Jun 09, 2003 12:31 am

300 AC(PE)

Post by reza ali » Sun Jun 22, 2003 8:15 pm

Mr. pupirev,

This is surprising that my code is presentation error.There is also your code which is Accepted.Tell me the difference.The codes are below:

//@begin_of_source_code

#include<iostream.h>
#include<string.h>

int main()
{
/*@JUDGE_ID: --------------- 300 C++ "Dynamic programming" */
unsigned long total;
int n,count,day,year,i,tmonth,dayname,tyear;
char dot,month[10],haab[19][10],tzolkin[20][10];

strcpy(haab[0],"pop");
strcpy(haab[1],"no");
strcpy(haab[2],"zip");
strcpy(haab[3],"zotz");
strcpy(haab[4],"tzec");
strcpy(haab[5],"xul");
strcpy(haab[6],"yoxkin");
strcpy(haab[7],"mol");
strcpy(haab[8],"chen");
strcpy(haab[9],"yax");
strcpy(haab[10],"zac");
strcpy(haab[11],"ceh");
strcpy(haab[12],"mac");
strcpy(haab[13],"kankin");
strcpy(haab[14],"muan");
strcpy(haab[15],"pax");
strcpy(haab[16],"koyab");
strcpy(haab[17],"cumhu");
strcpy(haab[18],"uayet");


strcpy(tzolkin[0],"imix");
strcpy(tzolkin[1],"ik");
strcpy(tzolkin[2],"akbal");
strcpy(tzolkin[3],"kan");
strcpy(tzolkin[4],"chicchan");
strcpy(tzolkin[5],"cimi");
strcpy(tzolkin[6],"manik");
strcpy(tzolkin[7],"lamat");
strcpy(tzolkin[8],"muluk");
strcpy(tzolkin[9],"ok");
strcpy(tzolkin[10],"chuen");
strcpy(tzolkin[11],"eb");
strcpy(tzolkin[12],"ben");
strcpy(tzolkin[13],"ix");
strcpy(tzolkin[14],"mem");
strcpy(tzolkin[15],"cib");
strcpy(tzolkin[16],"caban");
strcpy(tzolkin[17],"eznab");
strcpy(tzolkin[18],"canac");
strcpy(tzolkin[19],"ahau");


while(cin>>n)
{
if (n==0) break;

/*count=0;
while(count++<n)
{
cin>>day[count]>>dot>>month[count]>>year[count];
}*/

cout<<n<<endl;
count=0;
while(count++<n)
{

cin>>day>>dot>>month>>year;
if(year>=5000) {cout<<"out of limit";break;}
if(day>19) {cout<<"out of limit";break;}
if(strcmp(month,"uayet")==0) { if(day>4) {cout<<"out of limit";break;}}

for(i=0;i<=18;i++)
{
if(strcmp(month,haab)==0)
{
total=(unsigned long) day+1+(unsigned long)i*20+365*(unsigned long)year;
break;

}
}
if(total%260==0) tyear=(total/260)-1;
else tyear=total/260;
total=total%260;
tmonth=total%13; if(tmonth==0) tmonth=13;
dayname=total%20; if(dayname==0) dayname=20;
cout<<tmonth<<" "<<tzolkin[dayname-1]<<" "<<tyear<<endl;

}
}
return 0;
}
//@end_of_source_code



BUT THE CODE BELOW IS ACCEPTED.PLEASE TELL ME WHY?



#include<iostream.h>
#include<string.h>

int main()
{
/*@JUDGE_ID: ----------- 300 C++ "Dynamic programming" */
unsigned long total;
int n,count,day,year,i,tmonth,dayname,tyear;
char dot,month[10],haab[19][10],tzolkin[20][10];

strcpy(haab[0],"pop");
strcpy(haab[1],"no");
strcpy(haab[2],"zip");
strcpy(haab[3],"zotz");
strcpy(haab[4],"tzec");
strcpy(haab[5],"xul");
strcpy(haab[6],"yoxkin");
strcpy(haab[7],"mol");
strcpy(haab[8],"chen");
strcpy(haab[9],"yax");
strcpy(haab[10],"zac");
strcpy(haab[11],"ceh");
strcpy(haab[12],"mac");
strcpy(haab[13],"kankin");
strcpy(haab[14],"muan");
strcpy(haab[15],"pax");
strcpy(haab[16],"koyab");
strcpy(haab[17],"cumhu");
strcpy(haab[18],"uayet");


strcpy(tzolkin[0],"imix");
strcpy(tzolkin[1],"ik");
strcpy(tzolkin[2],"akbal");
strcpy(tzolkin[3],"kan");
strcpy(tzolkin[4],"chicchan");
strcpy(tzolkin[5],"cimi");
strcpy(tzolkin[6],"manik");
strcpy(tzolkin[7],"lamat");
strcpy(tzolkin[8],"muluk");
strcpy(tzolkin[9],"ok");
strcpy(tzolkin[10],"chuen");
strcpy(tzolkin[11],"eb");
strcpy(tzolkin[12],"ben");
strcpy(tzolkin[13],"ix");
strcpy(tzolkin[14],"mem");
strcpy(tzolkin[15],"cib");
strcpy(tzolkin[16],"caban");
strcpy(tzolkin[17],"eznab");
strcpy(tzolkin[18],"canac");
strcpy(tzolkin[19],"ahau");


while(cin>>n)
{
if (n==0) break;
cout<<n<<endl;
count=0;
while(count++<n)
{
cin>>day>>dot>>month>>year;

if(year>5000) {cout<<"out of limit";break;}
if(day>19) {cout<<"out of limit";break;}
if(strcmp(month,"uayet")==0) { if(day>4) {cout<<"out of limit";break;}}

for(i=0;i<=18;i++)
{
if(strcmp(month,haab)==0)
{
total=(unsigned long) day+(unsigned long)i*20+365*(unsigned long)year;
break;

}
}
if(total>259) tyear=(total/260);
else tyear=0;
total=total%260;
tmonth=total%13+1; //if(tmonth==0) tmonth=13;
dayname=total%20; //if(dayname==0) dayname=20;
cout<<tmonth<<" "<<tzolkin[dayname]<<" "<<tyear<<endl;

}
}
return 0;
}

Post Reply

Return to “Volume 3 (300-399)”