sicily 1783. Large is Better
#include<iostream>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
int main()
{
char ch[200];
int cases;
cin>>cases;
while(cases--)
{
cin>>ch;
int s,t,len=strlen(ch);
for(s=0;s<len;++s)
if(ch[s]!='0')
break;
for(t=s;t<len;++t)
if(ch[t]=='0')
break;
while(s<len)
{
sort(ch+s,ch+t,greater<char>());
for(s=t+1;s<len;++s)
if(ch[s]!='0')
break;
for(t=s;t<len;++t)
if(ch[t]=='0')
break;
}
cout<<ch<<endl;
}
return 0;
}
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
int main()
{
char ch[200];
int cases;
cin>>cases;
while(cases--)
{
cin>>ch;
int s,t,len=strlen(ch);
for(s=0;s<len;++s)
if(ch[s]!='0')
break;
for(t=s;t<len;++t)
if(ch[t]=='0')
break;
while(s<len)
{
sort(ch+s,ch+t,greater<char>());
for(s=t+1;s<len;++s)
if(ch[s]!='0')
break;
for(t=s;t<len;++t)
if(ch[t]=='0')
break;
}
cout<<ch<<endl;
}
return 0;
}