DIRECTI question

This code is giving correct on my computer but when I was submittin it was showing wrong answer . C an anybody tell me why it is wrong.

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

using namespace std;

int main()
{

int t=0;
scanf("%d",&t);
char** arr;
arr=(char **)malloc(41*sizeof(char *));
for(int i=0;i<41;i++)
	{
		arr[i]=(char *)malloc(50*sizeof(char));
	}
	
	string s;
	char name[50];
	cout<<"\n";
	
int n=0;
for(int i=0;i<t;i++)
{
	scanf("%d",&n);
	for(int j=0;j<=n;j++)
		cin.getline(arr[j],50,'\n');
	
	cout<<"Begin ";
	if(arr[n][0]=='L')
		{for(int k=5;arr[n][k]!='\0';k++)
			cout<<arr[n][k];
		}
	else if(arr[n][0]=='R')
		{for(int k=6;arr[n][k]!='\0';k++)
			cout<<arr[n][k];
		}
		cout<<"\n";
	for(int p=n-1;p>0;p--)
	{
		if(arr[p+1][0]=='L')cout<<"Right ";
		
		else if(arr[p+1][0]=='R')cout<<"Left ";
		int k;
		if(arr[p][0]=='L')k=5;
		else k=6;
		for(;arr[p][k]!='\0';k++)
			cout<<arr[p][k];
			cout<<"\n";
	}	
	cout<<"\n";
	

	
}

}

Somebody plz answer, whats wrong with this code.

Same with me too! The problem is very easy, so there isn’t problem with the algo. I think some functions behave differntly in the codechef environment :confused:

I did the same thing using different functions and now its working

You are printing an extra “\n” on line no. 21. (Below the “char name[50];”).