This is my code: https://ide.codingblocks.com/s/159641 What should I change?
One test case failing in string sort
@shruthi019 You are not lexicographically sorting it because of which your test case is not passing.
Consider a case:
4
ac
cc
bc
dc
Expected Output:
ac
bc
cc
dc
Your Output:
ac
cc
bc
dc
For this question you can make an array of strings and then sort it according to the condition that if there is a prefix match between two string, sort in decreasing order of length. Use C++ inbuilt sort function with a custom comparator something like this:
bool mycompare( string a, string b)
{
int l1=a.length();int l2=b.length();int flag=-1;
for(int i=0;i<min(l1,l2);i++){
if(a[i]!=b[i])
flag=0;
}
if(flag==-1) // means there is a prefix match
return l1>l2; // so sort decreasing order of length
else
return a<b; //sorting in normal dictionary order when no prefix match
}
Hope this helps