Loading Similar Posts
Question solution
bool compare(string &a,string &b)
{
//return a>b;
string x=a+b;
string y=b+a;
// cout<<a<<" "<<b<<" "<<x<<" "<<y<<endl;
return x>y;
/* cout<<a<<" "<<b<<endl;
if(a.length()==b.length())
return a>b;
else if(a.length()<b.length())
{
int x=a.length()-1;
for(int i=0;i<=x;i++)
{
if(a[i]!=b[i])
{
if(a[i]>b[i])
return a>b;
else
return b>a;
}
}
for(int i=a.length();i<b.length();i++)
{
if(a[x]>b[i])
return a>b;
}
return b>a;
}
else
{
int x=b.length()-1;
for(int i=0;i<=x;i++)
{
if(a[i]!=b[i])
{
if(a[i]>b[i])
return a>b;
else
return b>a;
}
}
for(int i=b.length();i<a.length();i++)
{
if(b[x]>a[i])
return b>a;
}
return a>b;
}*/
}
void solve()
{
int n;
cin>>n;
vector<int> v(n);
vector<string> s;
f(i,n)
{
cin>>v[i];
s.pb(to_string(v[i]));
}
sort(s.begin(),s.end(),compare);
cout<<s<<endl;
}