Guest User

Untitled

a guest
Feb 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. class Solution {
  2. public:
  3. string strWithout3a3b(int A, int B) {
  4. pair<int,int> cnt = {max(A, B), min(A,B)};
  5. pair<char,char> alph = {(A > B) ? 'a' : 'b', (A > B) ? 'b' : 'a'};
  6. string ans = "";
  7. while(cnt.first > 0 && cnt.second > 0 && cnt.first > cnt.second){
  8. ans.push_back(alph.first);
  9. ans.push_back(alph.first);
  10. cnt.first-=2;
  11. ans.push_back(alph.second);
  12. cnt.second--;
  13. }
  14. while(cnt.first > 0 || cnt.second > 0){
  15. if(cnt.first > 0) {
  16. ans.push_back(alph.first);
  17. cnt.first--;
  18. }
  19.  
  20. if(cnt.second > 0) {
  21. ans.push_back(alph.second);
  22. cnt.second--;
  23. }
  24. }
  25. return ans;
  26. }
  27. };
Add Comment
Please, Sign In to add comment