Ankit_132

B

Dec 27th, 2023
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7. #define pb     push_back
  8.  
  9. int main()
  10. {
  11.     _test
  12.     {
  13.         int n;
  14.         string s;
  15.         cin>>n>>s;
  16.  
  17.         string ans = "";
  18.  
  19.         int want = n/2 + 1;
  20.         int rem = n;
  21.  
  22.         for(auto e: s)
  23.         {
  24.             rem--;
  25.  
  26.             if(rem >= want)
  27.             {
  28.                 ans.pb('P');
  29.                 if(e == 'R')        want--;
  30.             }
  31.             else
  32.             {
  33.                 if(e == 'R')
  34.                     ans.pb('P');
  35.  
  36.                 if(e == 'P')
  37.                     ans.pb('S');
  38.  
  39.                 if(e == 'S')
  40.                     ans.pb('R');
  41.  
  42.                 want--;
  43.             }
  44.         }
  45.  
  46.         cout<<ans<<"\n";
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment