Doubt in String Sort

The code is running for the given sample input but the two test cases are not being passed.
Question
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.

Input Format
N(integer) followed by N strings.

Constraints
N<=1000

Output Format
N lines each containing one string.

Sample Input
3
bat
apple
batman
Sample Output
apple
batman
bat
Code https://ide.codingblocks.com/s/117945

@ratulhans hey rahul this thing will not work make a compare function which accept two string a ,string b as a
parameters and inside the functions these statements will used
if ( (a==b.substr(0,a.length())))
return b.length()>a.length();
else if((b==a.substr(0,b.length())))
return a.length()>b.length();

   return a<b;

what you do in main function is that sort your string array and pass them with custom compare function.

1 Like

Can you do the necessary modifications in the code ??

@ratulhans It so easy you can do it yourself just make a string arr,and sort the array with custom function suggested above.