Codeforces Round #494 (Div. 3) 1003B - Binary String Constructing Solution



 Problem Link:  https://codeforces.com/problemset/problem/1003/B\

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int main() {
  10. int a, b, x;
  11. cin >> a >> b >> x;
  12. if (x % 2 == 0) {
  13. if (a > b) {
  14. for (int i = 0; i < x / 2; i++) cout << "01";
  15. for (int i = 0; i < b - x / 2; i++) cout << "1";
  16. for (int i = 0; i < a - x / 2; i++) cout << "0";
  17. } else {
  18. for (int i = 0; i < x / 2; i++) cout << "10";
  19. for (int i = 0; i < a - x / 2; i++) cout << "0";
  20. for (int i = 0; i < b - x / 2; i++) cout << "1";
  21. }
  22. } else {
  23. if (a > b) {
  24. for (int i = 0; i < x / 2; i++) cout << "01";
  25. for (int i = 0; i < a - x / 2; i++) cout << "0";
  26. for (int i = 0; i < b - x / 2; i++) cout << "1";
  27. } else {
  28. for (int i = 0; i < x / 2; i++) cout << "10";
  29. for (int i = 0; i < b - x / 2; i++) cout << "1";
  30. for (int i = 0; i < a - x / 2; i++) cout << "0";
  31. }
  32. }
  33. }


No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.