String sort Logic

I have solved this problem with my own logic and got 100 but then I opened the editorial and saw a different logic . I want to know if my logic is right .

Here is a snippet :

#include <bits/stdc++.h>
using namespace std ;
bool comp(string s1 , string s2)
{
//cout << "Comparing " << s1 << " and " << s2 << endl;
if(s1.find(s2)!=std::string::npos)
{
return s1.length() > s2.length() ;
}
else
{
int a = s1.compare(s2);
if(a>0)
return 0 ;
else
return 1 ;
}
}
int main() {
int n ;
cin >> n ;
string s[n] ;
for(int i=0 ; i<n ;i++)
cin >> s[i] ;
sort(s , s+n) ;
sort(s , s+n , comp);
for(int j=0; j<n; j++)
cout << s[j] << endl ;
return 0;

}

Also why is score not reflected on leaderboards ?

Hi
yes your logic is correct

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.