Not able to solve case 2 pls help

#include
#include <string.h>
#include
using namespace std;
bool comparator(string a, string b)
{
int la = a.length();

if (a[0] == b[0])
{
    int f = 0;
    for (int i = 0; i < la; i++)
    {
        if (a[i] != b[i])
        {
            f = 1;
        }

        if (f == 0)
        {
            return a.length() > b.length();
        }
    }

}
    return a < b;

}

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, comparator);

for (int i = 0; i < n; i++)
{
    cout << s[i] << endl;
}
return 0;

}

hi @rounaqkhandelwal24


mismatch will take smaller string then larger string and checks if smaller is a part of larger string or not. In the if clause I am considering s1 to be smaller string and then whether it is a subset of s2 or not.

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.