Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save SuryaPratapK/e7211a71677eb30933ae9c22fda6bb55 to your computer and use it in GitHub Desktop.

Select an option

Save SuryaPratapK/e7211a71677eb30933ae9c22fda6bb55 to your computer and use it in GitHub Desktop.
//#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;
}
@Tasneem-Mohammad
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment