
300 - Maya Calendar
Moderator: Board moderators
Thanks!
Thanks mf! Changed that and got acc!
. I never knew i had so simple an error as the wrong names. The reason i didnt initialise like char a[]={"pop","nextmonth".... was that the line was very long and i thought the OJ may give an error if it was wrapped to the next line!

300 - Maya Calendar - WA
everything seems good, but i still get WA!
Code: Select all
#include <cstdio>
#include <string>
#include <map>
#include <cctype>
#include <iostream>
using namespace std;
string months[] = {"pop", "no", "zip", "zotz", "tzec",
"xul", "yoxkin", "mol", "chen", "yax",
"zac", "ceh", "mac", "kankin", "muan",
"pax", "koyab", "cumhu"};
string days[] = {"imix", "ik", "akbal", "kan", "chicchan",
"cimi", "manik", "lamat", "muluk", "ok",
"chuen", "eb", "ben", "ix", "mem",
"cib", "caban", "eznab", "canac", "ahau"};
int main()
{
map<string, int> haab;
for (int i = 0; i < 18; i++)
haab[months[i]] = 20*i;
haab["uayet"] = 18*20;
int N;
unsigned nod, year;
string mon;
char buf[128];
fgets(buf, sizeof buf, stdin);
sscanf(buf, "%d", &N);
for (int i = 0; i < N; i++)
{
char b[32];
int u = 0;
fgets(buf, sizeof buf, stdin);
sscanf(buf, "%u. %s %u", &nod, b, &year);
while (b[u] != '\0')
{
b[u] = tolower(b[u]);
u++;
}
mon = string(b);
unsigned yy = year*365 + haab[mon] + nod;
unsigned Tzyy = yy / 260;
yy = yy%260;
unsigned Tzdn = yy%13 + 1;
unsigned Tzmn = yy%20;
//printf("%u %s %u\n", Tzdn, days[Tzmn].c_str(), Tzyy);
cout<<Tzdn<<" "<<days[Tzmn]<<" "<<Tzyy<<endl;
}
//while (getchar() == '\n');
return 0;
}
-
- New poster
- Posts: 10
- Joined: Mon May 07, 2007 4:45 am
Hi I've been getting WA on this problem and it's really annoying
Can someone tell me if my algorithm is wrong or is there any other problems?
Thanks
edit: nvm, I got it
Can someone tell me if my algorithm is wrong or is there any other problems?
Thanks
Code: Select all
removed
wa 300
Hi I'm getting wrong answer in this, i try the input in the forums and it seems ok, what could be the mistake?
here is my code
here is my code
Code: Select all
#include <iostream>
#include <cstring>
int first(char month[], int dia, int ano);
void second(int dias);
void ini(char a[]);
int main()
{
int n=0;
scanf("%d\n",&n);
if(n>0)
printf("%d\n",n);
while(n-->0)
{
int dia=0, ano=0;
char month[15];
ini(month);
scanf("%d. %[abcdefghijklmnopqrstuvwxyz]s",&dia,&month);
scanf("%d\n",&ano);
second(first(month,dia,ano));
}
return 0;
}
void second(int dias)
{
int ano=dias/260, mes=0, dia=0;
mes=dias%20;
dia=dias%13;
printf("%d ",dia+1);
if(mes==0)
printf("imix");
else if(mes==1)
printf("ik");
else if(mes==2)
printf("akbal");
else if(mes==3)
printf("kan");
else if(mes==4)
printf("chicchan");
else if(mes==5)
printf("cimi");
else if(mes==6)
printf("manik");
else if(mes==7)
printf("lamat");
else if(mes==8)
printf("muluk");
else if(mes==9)
printf("ok");
else if(mes==10)
printf("chuen");
else if(mes==11)
printf("eb");
else if(mes==12)
printf("ben");
else if(mes==13)
printf("ix");
else if(mes==14)
printf("men");
else if(mes==15)
printf("cib");
else if(mes==16)
printf("caban");
else if(mes==17)
printf("eznab");
else if(mes==18)
printf("canac");
else if(mes==19)
printf("ahau");
printf(" %d\n",ano);
}
int first(char month[], int dia, int ano)
{
int res=0;
res+=365*ano;
if(strcmp(month,"pop")==0)
res+=dia;
else if(strcmp(month,"no")==0)
res+=dia+20;
else if(strcmp(month,"zip")==0)
res+=dia+40;
else if(strcmp(month,"zotz")==0)
res+=dia+60;
else if(strcmp(month,"tzec")==0)
res+=dia+80;
else if(strcmp(month,"xul")==0)
res+=dia+100;
else if(strcmp(month,"yoxkin")==0)
res+=dia+120;
else if(strcmp(month,"mol")==0)
res+=dia+140;
else if(strcmp(month,"chen")==0)
res+=dia+160;
else if(strcmp(month,"yax")==0)
res+=dia+180;
else if(strcmp(month,"zac")==0)
res+=dia+200;
else if(strcmp(month,"ceh")==0)
res+=dia+220;
else if(strcmp(month,"mac")==0)
res+=dia+240;
else if(strcmp(month,"kankin")==0)
res+=dia+260;
else if(strcmp(month,"muan")==0)
res+=dia+280;
else if(strcmp(month,"pax")==0)
res+=dia+300;
else if(strcmp(month,"koyab")==0)
res+=dia+320;
else if(strcmp(month,"cumhu")==0)
res+=dia+340;
else if(strcmp(month,"uayet")==0)
res+=dia+360;
return res;
}
void ini(char a[])
{
int x=0;
while(x<15)
a[x++]='\0';
}
-
- New poster
- Posts: 7
- Joined: Mon Jun 08, 2009 4:02 am
300 MAYA CALENDER Wrong Answer......:(
I'm solving 300 Maya Calender, but I keep having wrong answer...
Do you see any problem in the code below?
I've read all of the articles about the problem..please help!
Do you see any problem in the code below?

Code: Select all
import java.io.*;
import java.util.*;
public class P1008 {
public static void main(String[] args) throws IOException{
HashMap<String, Integer> haab = new HashMap();
HashMap<Integer, String> tzolkin = new HashMap();
/// Haab calender month ////
haab.put("pop",1);
haab.put("no",2);
haab.put("zip",3);
haab.put("zotz",4);
haab.put("tzec",5);
haab.put("xul",6);
haab.put("yoxkin",7);
haab.put("mol",8);
haab.put("chen",9);
haab.put("yax",10);
haab.put("zac",11);
haab.put("ceh",12);
haab.put("mac",13);
haab.put("kankin",14);
haab.put("muan",15);
haab.put("pax",16);
haab.put("koyab",17);
haab.put("cumhu",18);
haab.put("uayet",19);
/// Tzolkin calender day ////
tzolkin.put(1,"imix");
tzolkin.put(2,"ik");
tzolkin.put(3,"akbal");
tzolkin.put(4,"kan");
tzolkin.put(5,"chicchan");
tzolkin.put(6,"cimi");
tzolkin.put(7,"manik");
tzolkin.put(8,"lamat");
tzolkin.put(9,"muluk");
tzolkin.put(10,"ok");
tzolkin.put(11,"chuen");
tzolkin.put(12,"eb");
tzolkin.put(13,"ben");
tzolkin.put(14,"ix");
tzolkin.put(15,"mem");
tzolkin.put(16,"cib");
tzolkin.put(17,"caban");
tzolkin.put(18,"eznab");
tzolkin.put(19,"canac");
tzolkin.put(0,"ahau");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testCase = Integer.parseInt(br.readLine());
System.out.println(testCase);
for(int i=0; i<testCase; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
String firstToken = st.nextToken();
int haabDay = Integer.parseInt(firstToken.substring(0,firstToken.length()-1));
int haabMonth = haab.get(st.nextToken());
int year = Integer.parseInt(st.nextToken());
int absoluteDate = (year * 365) + (haabMonth-1) * 20 + (haabDay+1);
int tzolYear = absoluteDate / 260;
String tzolDayName = tzolkin.get(absoluteDate % 20);
int tzolDayNum = absoluteDate % 13;
if(tzolDayNum == 0) tzolDayNum = 13;
System.out.println(tzolDayNum + " " + tzolDayName + " " + tzolYear);
}
}
}
Re: Problem 300: Maya Calender
Who are getting WA 
can try this case
Input :
Output :

can try this case
Input :
Code: Select all
2
19. mac 0
19. mac 2
Code: Select all
2
13 ahau 0
2 ok 3
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!='\0';i++)s=s*10+(int)(ss-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!=32;i++)lon++;
for(int i=lon;d!=32;i++)
{
numss[i-lon]=d;
lon2++;
}
for(int i=lon+lon2;d!='\0';i++)
yy=yy*10+(int)(d-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[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;
}
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!='\0';i++)s=s*10+(int)(ss-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!=32;i++)lon++;
for(int i=lon;d!=32;i++)
{
numss[i-lon]=d;
lon2++;
}
for(int i=lon+lon2;d!='\0';i++)
yy=yy*10+(int)(d-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[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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: Problem 300: Maya Calender
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
Check input and AC output for thousands of problems on uDebug!
Re: 300 - Maya Calendar - WA. help me plw.
#include<stdio.h>
#include<string.h>
int main()
{
int d,m,y,i,t;
char haab[][10]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol", "chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu", "uayet"},tzolkin[][10]={"imix","ik","akbal","kan","chicchan","cimi", "manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib", "caban","eznab","canac","ahau"},mon[10];
freopen("300.txt","r",stdin);
scanf("%d",&t);
printf("%d\n",t);
while(t--)
{
while(scanf("%d. %s %d\n",&d,mon,&y)!=EOF)
{
for(i=0;i<19;i++)
{
if(!strcmp(haab,mon))
{
m=i;
break;
}
}
d+=(y*365)+(m*20)+1;
y=(y%260)?(d/260):(d/260)-1;
d%=260;
m=(d%20)?(d%20):20;
d=(d%13)?(d%13):13;
printf("%d %s %d\n",d,tzolkin[m-1],y);
}
}
return 0;
}
#include<string.h>
int main()
{
int d,m,y,i,t;
char haab[][10]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol", "chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu", "uayet"},tzolkin[][10]={"imix","ik","akbal","kan","chicchan","cimi", "manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib", "caban","eznab","canac","ahau"},mon[10];
freopen("300.txt","r",stdin);
scanf("%d",&t);
printf("%d\n",t);
while(t--)
{
while(scanf("%d. %s %d\n",&d,mon,&y)!=EOF)
{
for(i=0;i<19;i++)
{
if(!strcmp(haab,mon))
{
m=i;
break;
}
}
d+=(y*365)+(m*20)+1;
y=(y%260)?(d/260):(d/260)-1;
d%=260;
m=(d%20)?(d%20):20;
d=(d%13)?(d%13):13;
printf("%d %s %d\n",d,tzolkin[m-1],y);
}
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 300 - Maya Calendar - WA
Don't read from a file.
Check input and AC output for thousands of problems on uDebug!