Guest User

Untitled

a guest
Mar 23rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string ans;
  9. int boyz, girlz;
  10. cin >> boyz >> girlz;
  11. //Check - up for possibility
  12. if ((double)boyz / girlz > 2 || girlz / (double)boyz > 2){
  13. cout << "NO SOLUTION";
  14. exit(0);
  15. }
  16. bool choice;
  17. int sum = boyz + girlz, ans_size = ans.size();
  18. (boyz > girlz) ? choice = 1 : choice = 0;
  19. for (int i = 0; ans_size < sum; i++){
  20. // Case - boyz == girlz. Algorithm : BGBG...
  21. if (boyz == girlz){
  22. (i % 2 == 0) ? ans += 'B' : ans += 'G';
  23. //Case - boyz > girlz. Algorithm : BGBBG...
  24. } else if (choice){
  25. if (i == 0)
  26. ans += 'B';
  27. else {
  28. if (i % 2 == 0){
  29. (ans_size == sum - 1) ? ans += 'B' : ans += "BB";
  30. }
  31. else
  32. ans += 'G';
  33. }
  34. //Case - boyz < girlz. Algorithm : GBGGB...
  35. } else {
  36. if (i == 0)
  37. ans += 'G';
  38. else {
  39. if (i % 2 == 0){
  40. (ans_size == sum - 1) ? ans += 'G' : ans += "GG";
  41. }
  42. else
  43. ans += 'B';
  44. }
  45. }
  46. ans_size = ans.size();
  47. }
  48. cout << ans;
  49. return 0;
  50. }
Add Comment
Please, Sign In to add comment