daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest May 27th, 2018 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <string>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main(void)
  6. {
  7.     int A = 4;
  8.     int B = 8;
  9.     string dense, sparse;
  10.     dense = (A >= B) ? "a" : "b";
  11.     sparse = (A < B) ? "a" : "b";
  12.  
  13.     string output;
  14.     while (A >= 0 && B >= 0 && abs(A - B) >= 2) {
  15.         output += dense;
  16.         output += dense;
  17.         output += sparse;
  18.         if (dense == "a") {
  19.             A -= 2;
  20.             B -= 1;
  21.         } else {
  22.             A -= 1;
  23.             B -= 2;
  24.         }
  25.     }
  26.  
  27.     while (A > 0 && B > 0) {
  28.         output += dense;
  29.         output += sparse;
  30.         --A;
  31.         --B;
  32.     }
  33.  
  34.     if (A != B) {
  35.         output += dense;
  36.     }
  37.  
  38.     cout << output << endl;
  39.     return 0;
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top