Sir csn u pls tell what is the problem in this problemn coz it does not pass all test cases in STRRING SORT CHLLLENGE
#include
#include
#include
using namespace std;
bool compare (string a , string b)
{
if(a[0]!=b[0])
{
return a<b;
}
else
{
return a.length()>b.length();
}
}
int main() {
int n;
cin>>n;
cin.get();
string s[n];
for(int i=0;i<n;i++)
{
getline(cin,s[i]);
}
sort(s,s+n,compare);
for(int i=0;i<n;i++)
{
cout<<s[i]<<endl;
}
return 0;
}
String Sort - Challenge
hey @adityasharma07669 you are just comparing the first letter of the string, but you need to compare the whole string in order to compare via length
Please refer to this code if you are not sure how to do it: