fork download
  1. #include <iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<string>
  5. using namespace std;
  6. int num_max(string,string);
  7. int main()
  8. {
  9. int n;
  10. string str;
  11. cout<<"Enter number of non-negative numbers to be arranged : ";
  12. cin>>n;
  13. cout<<"\nEnter the numbers to be arranged : ";
  14. vector <string> vec;
  15. for(int k=0;k<n;k++)
  16. {
  17. cin>>str;
  18. vec.push_back(str);
  19. }
  20. sort(vec.begin(),vec.end(),num_max);
  21. cout<<"\nTheĀ  largest number formed combining entered numbers is ";
  22.  
  23. for(int I=0;I<vec.size();I++)
  24. cout<<vec[I];
  25. return 0;
  26. }
  27. int num_max(string A,string B)
  28. {
  29. string AB=A.append(B);
  30. string BA=B.append(A);
  31. if(AB.compare(BA)>0)
  32. return 1;
  33. else
  34. return 0;
  35.  
  36. }
Success #stdin #stdout 0s 4156KB
stdin
3 3 327 94
stdout
Enter number of non-negative numbers to be arranged : 
Enter the numbers to be arranged : 
The  largest number formed combining entered numbers is 943327