String-please tell solution using sort stl and compare function as parameter in sort function

Nishant is a very naughty boy in Launchpad Batch. One day he was playing with strings, and randomly shuffled them all. Your task is to help Nishant Sort all the strings ( lexicographically ) but if a string is present completely as a prefix in another string, then string with longer length should come first. Eg bat, batman are 2 strings and the string bat is present as a prefix in Batman - then sorted order should have - Batman, bat.

hello himanshu,
please check -> https://ide.codingblocks.com/s/206107

can you explain me how is comparator working ???

image

In while loop i m comparing i th characters of both the strings.
if they are equal then i am moving to next character (i+1 th)
otherwise if s1[i] > s2[i] then returning false
if s1[i] < s2[i] then return true

now if one string is prefix of other then the loop will execute completely and will not return anything.

so in the end after loop i m comparing their respective length