Help me to fix SIGSEGV error in TRAINSET problem

#include
#include<string.h>
using namespace std;
int d[20000];
char c[20000][5];
int main()
{
int t,n,j,k,count=1;

scanf("%d",&t);
for(int i=0;i<t;i++)
{
    scanf("%d",&n);
    
    scanf("%s %f",c[0],&d[0]);
    for(j=1;j<n;j++)
    {
        
        scanf("%s %f",c[j],&d[j]);
        for(k=j-1;k>=0;k--)
        {
            if((strcmp(c[j],c[k]))==0)
            {
                
                if(d[j]!=d[k])
                {
                 //   printf("c==c ");
                 break;
                }
                
            }    
            else
            {
                if(k>0)
                 {
                 //    printf("workign continue");
                     continue;
                 }
                else
                {
                //    printf("WOrking");
                    count++;
                }
                    
            }
        }
        
    }
    printf("%d \n",count);
}

}

This is my program it is showing correct output but still online compiler is showing run time error.Please help me out

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

https://www.codechef.com/viewsolution/29515750
Please check this out

1 Like

Thanks :slight_smile:

  1. N can be up to 25000, but you are only allocating space for N up to 20000; and
  2. |w_i| can be up to 5, and 5 chars is not enough space to hold a string of 5 characters read via scanf("%s", ...) due to the null-terminator.
1 Like

Sir, now it showing time limit exceeded what to do know.

Come up with a faster approach :slight_smile:

Edit:

Your latest submission is giving the wrong answer for the sample testcase - I suggest fixing that, first.

1 Like

@ssjgz you should keep this as your CC discuss template. XD

3 Likes