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

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

Post by Pupirev Sergei »

Both codes got AC.
How did you got PE?

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

surprising

Post by reza ali »

Mr. Pupirev,
This is the mystry. For your kind information I use Turbo C++ 3.0 compiler for coding and use online submatic 0.6 for submission.The first code , I got 2 times AC(PE) but your correction that is 2nd one I got only AC.Which one you use for coding and submission?
Try to explain it please.

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

Thanks

Post by reza ali »

MR. Pupirev
At last I got accepeted of my code copying from board.I don't know why such things happend. Anyway, thanks to you.

Ferdous
New poster
Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm
Location: Dhaka, Bangladesh
Contact:

300 - Maya Calendar

Post by Ferdous »

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

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

Post by helmet »

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

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal »

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.

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

Post by sidky »

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

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal »

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.

Ferdous
New poster
Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm
Location: Dhaka, Bangladesh
Contact:

Post by Ferdous »

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

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal »

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;

Ferdous
New poster
Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm
Location: Dhaka, Bangladesh
Contact:

Post by Ferdous »

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

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal »

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.

Ferdous
New poster
Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm
Location: Dhaka, Bangladesh
Contact:

Post by Ferdous »

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

zaj_tam
New poster
Posts: 5
Joined: Thu Dec 25, 2003 5:44 pm

300 -> Invalid memory reference

Post by zaj_tam »

I get runtime error:
Your program has died with signal 11 (SIGSEGV). Meaning:

Invalid memory reference

Before crash, it ran during 0.000 seconds.
I have no idea what this means :(

The code:

Code: Select all

#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>

using namespace std;

int get_month (char name [6],char haab_month [19][6]);

int main(int argc, char *argv[])
{

  int haab_year = 0;
  int tzolkin_year = 0;
  int num_entries;
  int current_month_haab;
 
  char haab_month [19][6];
 
  strcpy(haab_month[0], "pop");
  strcpy(haab_month[1], "no");
  strcpy(haab_month[2], "zip");
  strcpy(haab_month[3], "zotz");
  strcpy(haab_month[4], "tzec");
  strcpy(haab_month[5], "xul");
  strcpy(haab_month[6], "yoxkin");
  strcpy(haab_month[7], "mol");
  strcpy(haab_month[8], "chen");
  strcpy(haab_month[9], "yax");
  strcpy(haab_month[10], "zac");
  strcpy(haab_month[11], "ceh");
  strcpy(haab_month[12], "mac");
  strcpy(haab_month[13], "kankin");
  strcpy(haab_month[14], "muan");
  strcpy(haab_month[15], "pax");
  strcpy(haab_month[16], "koyab");
  strcpy(haab_month[17], "cumhu");
  strcpy(haab_month[18], "uayet");
 
 
  char tzolkin_day [20][8];
  int tzolkin_period_count = 13;
 
  strcpy(tzolkin_day[0], "imix");
  strcpy(tzolkin_day[1], "ik");
  strcpy(tzolkin_day[2], "akbal");
  strcpy(tzolkin_day[3], "kan");
  strcpy(tzolkin_day[4], "chicchan");
  strcpy(tzolkin_day[5], "cimi");
  strcpy(tzolkin_day[6], "manik");
  strcpy(tzolkin_day[7], "lamat");
  strcpy(tzolkin_day[8], "muluk");
  strcpy(tzolkin_day[9], "ok");
  strcpy(tzolkin_day[10], "chuen");
  strcpy(tzolkin_day[11], "eb");
  strcpy(tzolkin_day[12], "ben");
  strcpy(tzolkin_day[13], "ix");
  strcpy(tzolkin_day[14], "mem");
  strcpy(tzolkin_day[15], "cib");
  strcpy(tzolkin_day[16], "caban");
  strcpy(tzolkin_day[17], "eznab");
  strcpy(tzolkin_day[18], "canac");
  strcpy(tzolkin_day[19], "ahau");
 
  int buff_first [20];
  char buff_second [20][8];
  int buff_third [20];
 
  char a [3], b [6];
  int c;
  int announce;
  int iks = 0;
  scanf("%d", &announce);
  while ( iks < announce )
  {
    scanf("%s", a);
    scanf("%s", b);
    scanf("%d", &c);
 
    int haab_days;
    haab_days = get_month (b,haab_month) * 20 + atoi(a) + (365 * c);
 
    int tzolkin_first_conv = (haab_days + 1) % 13;
 
    char tzolkin_char_conv [8];
    strcpy(tzolkin_char_conv, tzolkin_day[(((haab_days + 1) % 20)-1)]);
 
    int tzolkin_year_conv = (haab_days - tzolkin_first_conv) / 260;
    if ( tzolkin_year_conv >= 1 ) { } else { tzolkin_year_conv = 0; }
    buff_first[iks] = tzolkin_first_conv;
    strcpy(buff_second[iks], tzolkin_char_conv);
    buff_third[iks] = tzolkin_year_conv;
    iks++;
  }
  for ( int pimp; pimp < iks; pimp++ )
  {
    printf("%d %s %d\n", buff_first[pimp], buff_second[pimp], 
buff_third[pimp]);
  }
  return 0;
}

int get_month (char name [6],char haab_month [19][6])
{
  int n = 0;
  while ( 0 != strcmp( name, haab_month[n] ) )
  {
    n++;
  }
  return n;
}

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal »

You get this RTE if your program attempts to access any location out of bounds. May be some bug in your code causing the program to access beyond the array lmits you've declared or may be something like that. And also chek the spellings and the ordering of months. Spelling mistake can cause RTE in this problem. I know some people who got RTE because of wrong spelling of Haab or Tzolkin months.

Post Reply

Return to “Volume 3 (300-399)”