Help me with SIGTSTP error

#include<stdio.h>
#include<string.h>

typedef struct dataset
{
char w[5];
int c0;
int c1;
}ds;

typedef struct mainset
{
char tw[5];
int s;
}ms;

int main()
{
int t, it, i, j, k, f, n, max, nc;
scanf("%d", &t);
for(it=0;it<t;++it)
{
scanf("%d", &n);
ds a[n];
ms b[n];
nc=0;
k=0;
for(i=0;i<n;++i)
{
scanf("%s %d", b[i].tw, &b[i].s);
}
for(i=0;i<n;++i)
{
f=1;
for(j=0;j<nc;++j)
{
if( strcmp(a[j].w, b[i].tw) ==0)
{
if(b[i].s==0) a[j].c0++;
else a[j].c1++;
f=0;
break;
}
}
if(f==1)
{
strcpy(a[k].w,b[i].tw);
if(b[i].s==0) { a[k].c0=1; a[k].c1=0; }
else { a[k].c0=0; a[k].c1=1; }
k++;
nc++;
}
}
max=0;
for(i=0;i<nc;++i)
max+= (a[i].c0>a[i].c1)? a[i].c0 : a[i].c1;
printf("%d \n",max);
}
return 0;
}

PROBLEM:
https://www.codechef.com/problems/TRAINSET

I can’t see any SIGSTOPs in your submission history for that problem, though it might be happening because char w[5]; does not leave room for a string of length 5 plus a null-terminator (similar for tw).

Edit:

Yep - the testcase:

1
2
dec 1
bcabd 1

crashes with your code on my machine :slight_smile:

1 Like