Srring sort problem

https://ide.codingblocks.com/s/246348 sir in this code when i am doing cout then total string getting printed is n-1 i am not able to understant why , and plz check the code for string sort

actually it is printing 10 strings
first string is ā€˜\n’
this is because when you provide n then there is ā€˜\n’ also present in the input buffer
so before taking other input you have to remove this ā€˜\n’ by using cin.get()

Modidfied Code

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course

Sir can u tell me approach to sort the string if a string is completely present as a prefix in another string with longer length should be come first in can you tell me how to modify my code so all test case can be pass

it is difficult to make apply that condition here
also time complexity is O(N^2) so even after doing changes here will not able to pass testcase
use STL (sort function with custom comparator ) to solve this

Reference code

1 Like

Thank u sir my doubt is clear

Sir i am not getting that why we are not checking for false condition in compair funtion and if two string are of different length then also it will write true because as i will be same for both the string so it will entere in if condition

@anuragavm123 is your doubt cleared?

@anuragavm123 here a simple compare function


if string present as a subset then sort descend else ascend
i hope its clear if yes dont forget to mark it as resolved and hit like :smiley:

1 Like

Yes sir i have some more doubt s in compair funtion

Sir i this compair funtion we are checking with the help of find funtion but why we are always returning a is great it may be there that b string can be great as we are checking for both

@anuragavm123 in question it is said to sort asc order and desc only in case if a mein b ya b mein a thats why did this

1 Like

Okay thank u sir now i am able to get

@anuragavm123 you are welcome :smiley:

1 Like