I am sorting the array lexogrphically and then printing the ans but it is giving wrong ans
Form Biggest Number using lexographical sorting
@17uec133 hey utkarsh make a bool compare function which accept two string as input and append one after another after compare them
@17uec133 hey utkarsh
simple compare function is
int compare(string a, string b){
string first = a.append(b);
string second = b.append(a);
return first.compare(second) >0 ? 1:0;
}
Why s1>s2 is not working while after appending it works?
@17uec133 hey utkarsh
A simple solution that comes to our mind is to sort all numbers in descending order, but simply sorting doesn’t work. For example, 548 is greater than 60, but in output 60 comes before 548. As a second example, 98 is greater than 9, but 9 comes before 98 in output.
So how do we go about it? The idea is to use any comparison based sorting algorithm. In the used sorting algorithm, instead of using the default comparison, write a comparison function myCompare() and use it to sort numbers. Given two numbers X and Y, how should myCompare() decide which number to put first – we compare two numbers XY (Y appended at the end of X) and YX (X appended at the end of Y). If XY is larger, then X should come before Y in output, else Y should come before. For example, let X and Y be 542 and 60. To compare X and Y, we compare 54260 and 60542. Since 60542 is greater than 54260, we put Y first
take 60 and 542 as example. If I sort both of them lexographically the the ans will be 60 542, right?