Created
March 7, 2020 21:40
-
-
Save SuryaPratapK/e7211a71677eb30933ae9c22fda6bb55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#include <iostream> | |
#include<bits/stdc++.h> | |
using namespace std; | |
bool comparator(string first,string second) | |
{ | |
string one = first+second; | |
string two = second+first; | |
int i=0; | |
while(one[i] && two[i]) | |
{ | |
if(one[i]>two[i]) | |
return true; | |
else if(one[i]<two[i]) | |
return false; | |
++i; | |
} | |
return false; | |
} | |
int main() { | |
//code | |
int tc; | |
cin>>tc; | |
while(tc--) | |
{ | |
int len; | |
vector<string> arr; | |
//Take Array inputs | |
int i; | |
string temp; | |
cin>>len; | |
for(i=0;i<len;++i) | |
{ | |
cin>>temp; | |
arr.push_back(temp); | |
} | |
sort(arr.begin(),arr.end(),comparator); | |
for(i=0;i<len;++i) | |
cout<<arr[i]<<" "; | |
cout<<"\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
class Solution {
public:
string largestNumber(vector& nums) {
vectornums1;
string st="";
for(int i=0;i<nums.size();i++){
nums1.push_back(to_string(nums[i]));
}
for(int i=0;i<nums1.size();i++){
for(int j=i+1;j<nums1.size();j++){
if(nums1[i]+nums1[j]<nums1[j]+nums1[i])
swap(nums1[i],nums1[j]);
}
}
for(auto p:nums1){
st+=p;
}
return (st[0]=='0'?"0":st);
}
};