Codeforces Round #494 (Div. 3) 1003B - Binary String Constructing Solution
Problem Link: https://codeforces.com/problemset/problem/1003/B\
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int a, b, x;
- cin >> a >> b >> x;
- if (x % 2 == 0) {
- if (a > b) {
- for (int i = 0; i < x / 2; i++) cout << "01";
- for (int i = 0; i < b - x / 2; i++) cout << "1";
- for (int i = 0; i < a - x / 2; i++) cout << "0";
- } else {
- for (int i = 0; i < x / 2; i++) cout << "10";
- for (int i = 0; i < a - x / 2; i++) cout << "0";
- for (int i = 0; i < b - x / 2; i++) cout << "1";
- }
- } else {
- if (a > b) {
- for (int i = 0; i < x / 2; i++) cout << "01";
- for (int i = 0; i < a - x / 2; i++) cout << "0";
- for (int i = 0; i < b - x / 2; i++) cout << "1";
- } else {
- for (int i = 0; i < x / 2; i++) cout << "10";
- for (int i = 0; i < b - x / 2; i++) cout << "1";
- for (int i = 0; i < a - x / 2; i++) cout << "0";
- }
- }
- }
No comments