String sort problem

mam why my cde id failling for test case 2
#include
#include
#include
using namespace std;

int main()
{
int n;
cin>>n;
cin.get();
int t;
char a[n][1000];
for(int i=0;i<n;i++)
{
cin.getline(a[i],1000);
}
for(int i=0;i<n;i++)
{
char d=a[i][0];
for(int j=i+1;j<n;j++)
{
if(d>a[j][0])
{
d=a[j][0];
t=j;
}
else if(d==a[j][0])
{
int k=strlen(a[j]);
int l=strlen(a[i]);
if(k>l)
{
d=a[j][0];
t=j;
}
else{
t=d;
}
}
}
swap(a[i],a[t]);
}
for(int i=0;i<n;i++)
{
cout<<a[i]<<endl;
}
}

@YASHMATHURIA123

  1. else part in line 37 is wrong, why are you making t=d ? d is char, there is no link between these two
  2. you are just checking only 1st characters, if 1st character of two string are same then you are checking string with greater length. But It is clearly mentioned in the question that if one string is completely prefix of another then only you have to check for length

sir so what is right. sir i just delete that t=d also but still does not work.

@YASHMATHURIA123
Have you considered 2nd point. Compare whole string not just one single character. Try to think about it otherwise i’ll modify your code.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.