栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

CodeForces - 1003B Binary String Constructing

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CodeForces - 1003B Binary String Constructing

B. Binary String Constructing
time limit per test1 second
memory limit per test256 megabytes

You are given three integers a, b and x. Your task is to construct a binary string s of length n=a+b such that there are exactly a zeroes, exactly b ones and exactly x indices i (where 1≤i

For example, for the string “01010” there are four indices i such that 1≤i

Recall that binary string is a non-empty sequence of characters where each character is either 0 or 1.

Input
The first line of the input contains three integers a, b and x (1≤a,b≤100,1≤x

Output
Print only one string s, where s is any binary string satisfying conditions described above. It is guaranteed that the answer always exists.

Examples
input
2 2 1
output
1100
input
3 3 3
output
101100
input
5 3 6
output
01010100
Note
All possible answers for the first example:
1100;
0011.
All possible answers for the second example:
110100;
101100;
110010;
100110;
011001;
001101;
010011;
001011.

问题链接:CodeForces - 1003B Binary String Constructing
问题简述:(略)
问题分析:(略)
AC的C++语言程序如下:


#include 

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int a, b, x;
    cin >> a >> b >> x;
    if (x & 1) {
        if (a >= b) {
            cout << '0';
            a--;
            while (x > 2) {
                cout << "10";
                a--, b--, x -= 2;
            }
            while (a--) cout << '0';
            while (b--) cout << '1';
        } else {
            cout << '1';
            b--;
            while (x > 2) {
                cout << "01";
                a--, b--, x -= 2;
            }
            while (b--) cout << '1';
            while (a--) cout << '0';
        }
    } else {
        if (a >= b) {
            cout << '0';
            a--;
            while (x > 2) {
                cout << "10";
                a--, b--, x -= 2;
            }
            while (b--) cout << '1';
            while (a--) cout << '0';
        } else {
            cout << '1';
            b--;
            while (x > 2) {
                cout << "01";
                a--, b--, x -= 2;
            }
            while (a--) cout << '0';
            while (b--) cout << '1';
        }
    }

    return 0;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/767828.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号