 # Alice's promotion!

Mr. Smith is the manager of Alice. Mr. Smith loves numbers and codes. He gives Alice a list of N non-negative numbers and asks him to arrange them such that they form largest possible number. To impress Smith and get promotion, he needs to write the code. Can you help Alice in getting promotion? The result is going to be very large, hence return the result in the form of a string.

The problem is to arrange the given array of numbers so that it yields the largest value.

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.

#include
#include
#include
#include
using namespace std;

int myCompare(string X, string Y)
{

``````string XY = X.append(Y);
string YX = Y.append(X);

return XY.compare(YX) > 0 ? 1: 0;
``````

}

void printLargest(vector arr)
{

``````sort(arr.begin(), arr.end(), myCompare);

for (int i=0; i < arr.size() ; i++ )
cout << arr[i];
``````

}

int main()
{
int t,n;
cin>>t;

``````while(t--)
{
cin>>n;

vector<string> arr;
for(int i=0;i<n;i++)
{
string str;
cin>>str;
arr.push_back(str);
}

printLargest(arr);
cout<<endl;

}
``````

return 0;
}

//