Sort String Problem

I have run the code but test case 1 not pass

this is my code

#include
#include
#include
using namespace std;

bool comp(string a,string b){

	   if(a[0]==b[0]){
		    
			return a.length() >b.length();

}

  return a<b;// Assending order

}

int main(){
	 
	 int n;
	 cin >>n;
	 string a[1000];

	 cin.get();

	 for(int i=0;i<n;i++){
		   
		   getline(cin,a[i]);
	 }
	 
	  sort(a,a+n,comp);
	  for(int i=0;i<n;i++){
		   
		   cout << a[i] << endl;
	  }
	       
	  return 0;
}

@faizan_1402 just comparing first letter wont work. Use string::find() function to see if a is a substring of b or not.

Can solve using swap function ?

@faizan_1402 please explain how?
you have to see if a given string is a substring of the other string or not, find function works best for that

I was not use find function ,used the npos function

if(a.find(b)!=string::npos or b.find(a)!=string::npos){
return a.length() > b.length();
}

@faizan_1402 what is your doubt? npos is not a function it is a value returned by the find function if substring isnt found

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.