Theramore

Problem Description

  *Those blood-soaked shores of Kalimdor is like a ghost haunting Jaina Proudmoore ever since the day she pushed her father into hell.*

  *Now, standing in front of the devastated ruins of Theramore, she knew how naive she had been to want peace.*

  *The Focusing Iris. It was the most brutal and cowardly killing method Jaina could imagine.*

  *The Horde wants war. They will do anything to destroy us. But if this is all they want, Jaina will be pleased to offer them a big one.*


The warships of the Horde can be described as a string s which contains only '0' and '1', denoting the small warship and the large warship. Jaina can perform some magic to the string. In one magic, she chooses an arbitrary interval with odd length and reverse it. Jaina can perform this magic as many times as she likes.

Jaina wants the small warships to be in the front, since they are easier to destroy. She asks for your help, and you need to tell her the lexicographically smallest string that she can obtain.

Note: in this problem, suppose two sequences s and t both have length n, then s is lexicographically smaller than t if there exists a position i(1≤i≤n) such that sj=tj for all 1≤j<i and si=′0′,ti=′1′.

Input

The input consists of multiple test cases.

The first line contains an integer T (1≤T≤10) denoting the number of test cases.

Each test case consists of only one line containing a string s (|s|≤10^5).

Output

Output one line containing the lexicographically smallest string that you can get.

Sample Input

2
101001
01101100000000101010

Sample Output

001011
00000000001010101111

Hint

In the first test case, Jaina performs magic to the interval [3,5] and the string is changed to 100011. Then Jaina performs magic to the interval [1,3] and the string is changed to 001011.

题解:偶数位和奇数位分别字典序最小即可,主要是aa++和bb++技巧。

#include<bits/stdc++.h>
using namespace std;
string s;
string a,b;
typedef long long ll;
ll aa,bb;
ll A,B;
int main()
{
	int _;
	cin>>_;
	while(_--)
	{
		aa=0,bb=0;
		A=0,B=0;
		cin>>s;
		ll len=s.size();
		//cout<<len<<endl;
		for(ll i=0;i<len;i++)
		{
			if(i%2)//偶数位 
			{
				//cout<<"A"<<endl;
				if(s[i]=='0')
				{
					aa++;
					//cout<<"aa"<<endl;
				}
				A++;
			}
			else
			{
				//cout<<"B"<<endl;
				if(s[i]=='0')
				{
					bb++;
					//cout<<"bb"<<endl;
				}
				B++;
			}
		}
		//cout<<"aa="<<aa<<" "<<"bb="<<bb<<endl;
		for(ll i=0;i<aa;i++)
		{
			s[i*2+1]='0';
		}
		for(ll i=aa;i<A;i++)
		{
			s[i*2+1]='1';
		}
		for(ll i=0;i<bb;i++)
		{
			s[i*2]='0';
		}
		for(ll i=bb;i<B;i++)
		{
			s[i*2]='1';
		}
		cout<<s<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TherAndI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值