
thx for the tips anyway

Moderator: Board moderators
Code: Select all
Your program has died with signal 11 (SIGSEGV). Meaning:
Invalid memory reference
Before crash, it ran during 0.002 seconds.
Code: Select all
/* @JUDGE_ID: 40671PZ 300 C++ */
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
using namespace std;
int get_month (char name [7],char haab_month [19][7]);
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][7];
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][9];
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][9];
int buff_third [20];
char a [4], b [7];
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 [9];
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 [7],char haab_month [19][7])
{
int n = 0;
while ( 0 != strcmp( name, haab_month[n] ) )
{
n++;
}
return n;
}
No, it means 6 chars smth[0] .. smth[5].zaj_tam wrote:Anyway, i dont get it. The string is 6 chars long. The array is smth[6] - > that means 7 chars: smth[0] smth[1] smth[2] smth[3] smth[4] smth[5] smth [6], doesnt it? Or is the last one terminating zero for array? I guess so.
Code: Select all
$ g++ generate.cpp -o generate
$ ./generate > myinput
Code: Select all
$ ./a.out < myinput > myoutput
Code: Select all
#include <stdio.h>
#include <string.h>
typedef struct
{
int day;
char dname[10];
int year;
} Date;
char * mnth[] = { "", "pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", \
"mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan",\
"pax", "koyab", "cumhu"
};
char * days[] = { "", "imix", "ik", "akbal", "kan", "chicchan", "cimi", \
"manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix",\
"mem", "cib", "caban", "eznab", "canac", "ahau"
};
/* @param darr: pointer to an array of structure date
* @param n: no of input dates to read in
*/
void read_input(Date * darr, int n)
{
int i = 0;
for(i = 0; i < n; i++)
scanf("%d%*c%s%d", &darr[i].day, darr[i].dname, &darr[i].year);
return;
}
/* @param darr: arrays of input Haab dates
* @param n: no of input dates
*/
void find_tzolkin_date(Date * darr, int n)
{
int i = 0, m = 0, d = 0, y = 0;
unsigned long t = 0;
printf("%d\n", n);
for(i = 0; i < n; i++)
{
m = get_mnth_indx(darr[i].dname);
if(m > 0)
{
t = (darr[i].year * 365) + ((m - 1) * 20) + darr[i].day + 1;
m = t % 20;
d = t % 13;
y = t / 260;
printf("%d %s %d\n", d, days[m], y);
}
else
fprintf(stderr, "%s: month index negative !\n", __FUNCTION__);
}
return;
}
/* @param name: name of the month, whos index is expected */
int get_mnth_indx(char * name)
{
int i = 0;
for(i = 1; i < 20; i++)
{
if(strcmp(name, mnth[i]) == 0)
return (i);
}
return (-1);
}
/* @param argc: no of command line arguments
* @param argv: array of command line arguments
*/
int main(int argc, char * argv[])
{
int no = 0;
Date * arr = NULL;
scanf("%d", &no);
arr = malloc(no * sizeof(Date));
if(arr != NULL)
{
read_input(arr, no);
find_tzolkin_date(arr, no);
}
return (0);
}