My code for problem code ROWCOLOP or http://ww2.codechef.com/status/ROWCOLOP is:
#include<stdio.h>
#include<string.h>
int main()
{
long n,q;
scanf("%ld %ld",&n,&q);
char op[6];
long long mat[n][n];
int k,l;
for(k=0;k<n;k++)
for(l=0;l<n;l++)
mat[k][l]=0;
int x;
long r,c,o;
int i;
for(i=0;i<q;i++)
{
scanf("%s %ld %d",op,&o,&x);
if(strcmp("RowAdd",op))
{ r=o;
int j;
for(j=0;j<n;j++)
mat[r][j]+=x;
}
else if(strcmp("ColAdd",op))
{ c=o;
int j;
for(j=0;j<n;j++)
mat[j][c]+=x;
}
}
long max=mat[0][0];
for(k=0;k<n;k++)
for(l=0;l<n;l++)
if(mat[k][l]>max)
max=mat[k][l];
printf("%ld",max);
for(k=0;k<n;k++)
{
for(l=0;l<n;l++)
printf("%ld ",mat[k][l]);
printf("\n");
}
return 0;
}
I am able to run this program successfully on DevC++ on my PC, but on codechef it is giving a run-time error of SIGSEGV. Please help me to locate the problem.