#include
#include
using namespace std;
bool comparator(string s1, string s2)
{
if (s1[0] == s2[0]) // if first character is same, then sort according to length
return s1.length() > s2.length();
else // else sort lexicographically
return s1 < s2;
}
int main()
{
int n;
cin >> n;
string a[n];
if (n <= 100)
{
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
}
cout << endl;
sort(a, a + n,comparator);
for (int i = 0; i < n; i++)
{
cout << a[i] << endl;
}
return 0;
}
why my second test case failed