Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- string ans;
- int boyz, girlz;
- cin >> boyz >> girlz;
- //Check - up for possibility
- if ((double)boyz / girlz > 2 || girlz / (double)boyz > 2){
- cout << "NO SOLUTION";
- exit(0);
- }
- bool choice;
- int sum = boyz + girlz, ans_size = ans.size();
- (boyz > girlz) ? choice = 1 : choice = 0;
- for (int i = 0; ans_size < sum; i++){
- // Case - boyz == girlz. Algorithm : BGBG...
- if (boyz == girlz){
- (i % 2 == 0) ? ans += 'B' : ans += 'G';
- //Case - boyz > girlz. Algorithm : BGBBG...
- } else if (choice){
- if (i == 0)
- ans += 'B';
- else {
- if (i % 2 == 0){
- (ans_size == sum - 1) ? ans += 'B' : ans += "BB";
- }
- else
- ans += 'G';
- }
- //Case - boyz < girlz. Algorithm : GBGGB...
- } else {
- if (i == 0)
- ans += 'G';
- else {
- if (i % 2 == 0){
- (ans_size == sum - 1) ? ans += 'G' : ans += "GG";
- }
- else
- ans += 'B';
- }
- }
- ans_size = ans.size();
- }
- cout << ans;
- return 0;
- }
Add Comment
Please, Sign In to add comment