CF 976A Minimum Binary Number题解

CF 976A Minimum Binary Number


time limit per test : 1 second
memory limit per test : 256 megabytes
input : standard input
output : standard output

Description

String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".

You are given a correct string s.

You can perform two different operations on this string:

  1.swap any pair of adjacent characters (for example, "101"->"110");

  2.replace "11" with "1" (for example, " 110"->" 10").
Let val(s) be such a number that s is its binary representation.

Correct string a is less than some other correct string b iff val(a) < val(b).

Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).

Input

The first line contains integer number n (1 ≤ n ≤ 100) — the length of string s.

The second line contains the string s consisting of characters "0" and "1". It is guaranteed that the string s is correct.

Output

Print one string — the minimum correct string that you can obtain from the given one.

Example

input

4
1001

output

100

input

1
1

output

1

Note

In the first example you can obtain the answer by the following sequence of operations: "1001"-> "1010"->"1100"->"100".

In the second example you can't obtain smaller answer no matter what operations you use.

Solution

  思路:

  分别统计1和0的个数,如果1的个数大于1则先输出一个1再输出所有0(因为只要有2个1存在都可缩减为一个1),反之输出一个0,即只存在0。

#include<iostream>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

int main(){
    ll t;
    cin>>t;

    string temp;
    cin>>temp;
    int c1=0,c0=0;
    for(int i=0;i<temp.length();i++){
        if(temp[i]=='1') c1++;
        else c0++;
    }

    if(c1>=1) cout<<1;
    else{
        cout<<0<<endl;
        return 0;
    }

    for(int i = 0;i<c0;i++) cout<<0;

    return 0;
}
算法题解 文章被收录于专栏

主要发布算法题解,题目来源牛客、codeforces、洛谷、Atcoder、leetcode

全部评论

相关推荐

牛至超人:把哈工大,再加大加粗,看见闪闪发光的哈工大字样,面试官直接流口水
投递字节跳动等公司6个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务