just take numbers as string and sort them.for comparision
let string a,b;
bool cmp(string &a,string &b)
{
foi(min(a.length(),b.length())
{
if(a[i]>b[i])
return true;
else if(b[i]>a[i])
return false;
}
}
This won’t quite work. You need to handle strings of different lengths slightly differently.
However it’s possible to bring all strings to maximum length, sort those, then only feed the appropriate part of each string into the result. CodeChef: Practical coding for everyone
You are right. Took me a while to get a failing case but finally found one.
I also like this approach:
https://www.codechef.com/viewsolution/17354973
This is a very trivial question. Just define a compartor function, that converts the two integers into strings and then compare. All you need to do in comparator is
s1=to_string(a)
s2=to_string(b)
if(s1+s2>s2+s1)
return true
Else
Return false
Just sort your array using this compartor function and you are done.