You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').

You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).

For example, for string "010210" we can perform the following moves:

  • "010210" →→ "100210";
  • "010210" →→ "001210";
  • "010210" →→ "010120";
  • "010210" →→ "010201".

Note than you cannot swap "02" →→ "20" and vice versa. You cannot perform any other operations with the given string excluding described above.

You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).

String aa is lexicographically less than string bb (if strings aa and bb have the same length) if there exists some position ii (1≤i≤|a|1≤i≤|a|, where |s||s| is the length of the string ss) such that for every j<ij<i holds aj=bjaj=bj, and ai<biai<bi.

Input

The first line of the input contains the string ss consisting only of characters '0', '1' and '2', its length is between 11 and 105105 (inclusive).

Output

Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).

Examples

Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20

开始时想的过于狭隘了,局部分析未果的情况下,没有做到整体的去分析。

对 0 1 2 的特点进行分析,1 既可以与 0 交换 ,也可以与 2 交换 ,所以说 1 可以出现在字符串的任意位置,为了使字符串的字典序小,1 必定要出现在 2 的前面,且要出现在第一个 2 的前面,所以 1 的位置就确定了。
再看 0 2 ,因为所有的 1 已经都被抽到了第一个 2 的前面,且 2 不能借助 1 使它本身换到 0 的后面(以 2 1 0为例),所以,第一个 2 后面的序列是不变的。
再看第一个 2 前面的序列,显然,第一个 2 之前的 0 要在所有的 1 之前。
分析完毕。 切入点:0 1 2 的特点、字符串的格式
 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double e=exp();
const int N = ; char con[];
int main()
{
int i,p,j,n,k;
int head,tail,a=,b=,flag; scanf("%s",con);
k=strlen(con);
for(i=;i<k;i++)
{
if(con[i]=='')
a++;
}
flag=;
for(i=;i<k;i++)
{
if(con[i]=='')
printf("");
else if(con[i]==''&&flag==)
{
for(j=;j<=a;j++)
printf("");
printf("");
flag=;
}
else if(con[i]==''&&flag==)
{
printf("");
}
}
if(flag==)
{
for(i=;i<=a;i++)
printf("");
}
return ;
}
  

CodeForces - 1009B Minimum Ternary String的更多相关文章

  1. Codeforces ~ 1009B ~ Minimum Ternary String (思维)

    题意 给你一个只含有0,1,2的字符串,你可以将"01"变为"10","10"变为"01","12" ...

  2. codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题

    http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...

  3. B. Minimum Ternary String (这个B有点狠)

    B. Minimum Ternary String time limit per test 1 second memory limit per test 256 megabytes input sta ...

  4. CF1009B Minimum Ternary String 思维

    Minimum Ternary String time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. Educational Codeforces Round 47 (Rated for Div. 2) :B. Minimum Ternary String

    题目链接:http://codeforces.com/contest/1009/problem/B 解题心得: 题意就是给你一个只包含012三个字符的字符串,位置并且逻辑相邻的字符可以相互交换位置,就 ...

  6. Balanced Ternary String CodeForces - 1102D (贪心+思维)

    You are given a string ss consisting of exactly nn characters, and each character is either '0', '1' ...

  7. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  8. 牛客多校第四场 A Ternary String

    题目描述 A ternary string is a sequence of digits, where each digit is either 0, 1, or 2. Chiaki has a t ...

  9. 2018牛客网暑期ACM多校训练营(第四场) A - Ternary String - [欧拉降幂公式][扩展欧拉定理]

    题目链接:https://www.nowcoder.com/acm/contest/142/A 题目描述 A ternary string is a sequence of digits, where ...

随机推荐

  1. Iaas

    IaaS(Infrastructure as a Service),即基础设施即服务. 消费者通过Internet 可以从完善的计算机基础设施获得服务.这类服务称为基础设施即服务.基于 Interne ...

  2. #46 delete(动态规划+树状数组)

    二维的dp非常显然,但这也没有什么优化的余地了. 注意到最后的方案中只有产生贡献的位置是有用的,剩下的部分可以在该范围内任意选取. 所以我们考虑设f[i]为i号位最后产生贡献的答案,则f[i]=max ...

  3. c++11 智能指针 unique_ptr、shared_ptr与weak_ptr

    c++11 智能指针 unique_ptr.shared_ptr与weak_ptr C++11中有unique_ptr.shared_ptr与weak_ptr等智能指针(smart pointer), ...

  4. IBatisNet 缓存使用

    参考:http://www.cnblogs.com/xiaogangqq123/archive/2011/06/30/2094905.html <?xml version="1.0&q ...

  5. BZOJ3155:Preprefix sum——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=3155 最朴素的想法是两棵树状数组,一个记录前缀和,一个记录前缀前缀和,但是第二个我们非常不好修改 ...

  6. 【BZOJ1801】【Ahoi2009】chess 中国象棋

    Time Limit: 10 Sec Memory Limit: 64 MB Description 在N行M列的棋盘上,放若干个炮可以是0个,使得没有任何一个炮可以攻击另一个炮. 请问有多少种放置方 ...

  7. 解题:JSOI 2008 Blue Mary的战略地图

    题面 这大概不算是从零开始的DP学习系列,这不是最大子矩形吗=.= 定义$dp[x][y][xx][yy]$表示第一张地图中右下角为$(x,y)$,第二张地图中右下角为$(xx,yy)$的最大公共子矩 ...

  8. 【bzoj4084】【sdoi2015】双旋转字符串

    题解 首先题中说了$n>=m$; 分成的循环串左右两边为本质相同的单循环串循环串,分别长为$l = \frac{n + m}{2} $; 所以$S$串的前$l$位为双循环串的一半$S1$,后一半 ...

  9. php获取星期几周几

    PHP星期几获取代码: date("l"); //data就可以获取英文的星期比如Sundaydate("w"); //这个可以获取数字星期比如123,注意0是 ...

  10. Docker login报错一例

    在一台ubuntu 18.04上执行docker login 登录镜像仓库的时候,抛出如下异常: error getting credentials - err: exit status 1, out ...