Advertisement
Zeinab_Hamdy

Acc2

Dec 14th, 2022
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned ll
  5. #define nl "\n"
  6. #define sz(x) x.size()
  7. #define NumOfDigit(w) log10(w) + 1
  8. #define fill(arr, val)  memset(arr, val , sizeof(arr))
  9. #define PI 3.141592654
  10. #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
  11. #define all(v) v.begin(), v.end()
  12. #define rall(v) v.rbegin(), v.rend()
  13. #define fi first
  14. #define se second
  15. #define cin(v) for (auto&i:v) cin >> i;
  16. #define cout(v) for (auto&i:v) cout << i << " ";
  17. #define fixed(n) fixed << setprecision(n)
  18. #define MOD  1000000007
  19.  
  20.  
  21. void IO(){
  22.     ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  23. }
  24. void files(){
  25.     //freopen("filename.in" , "r" ,stdin);
  26.             #ifndef ONLINE_JUDGE
  27.             freopen("input.txt", "r", stdin);  freopen("output.txt", "w", stdout);
  28.             #endif
  29. }
  30. bool prime(ll n){
  31.     if(n==2 || n==3) return true;
  32.     if(n<2 || n%2==0  ) return false;
  33.     for(int i=3;i<=sqrt(n);i+=2)   if(n%i==0) return false;
  34.     return true;
  35. }
  36.  
  37. bool cmp(pair < string , int > p1 , pair < string , int > p2){
  38.     return p1.second > p2.second;
  39. }
  40.  
  41.  
  42. void solve(){
  43. int n; cin >> n;
  44. string s;   cin >> s;
  45. int cnt=0;
  46.  
  47. for(int i=0;i<n-1;i++){
  48.     if(s[i]==s[i+1]){
  49.         cnt++;
  50.       if(i == n-2 ){
  51.           if(s[i]=='R') s[i+1]='G';
  52.           else if(s[i]=='G') s[i+1]='R';
  53.           else s[i+1]='R';
  54.           break;
  55.       }
  56.                 if(s[i+2]=='B' and s[i+1]=='R') s[i+1]='G' ;
  57.                 else if(s[i+2]=='R' and s[i]=='B') s[i+1]='G' ;
  58.                 else if(s[i+2]=='G' and s[i]=='R') s[i+1]='B' ;
  59.                 else if(s[i+2]=='R' and s[i]=='G') s[i+1]='B' ;
  60.                 else if(s[i+2]=='B' and s[i]=='G') s[i+1]='R' ;
  61.                 else if(s[i+2]=='G' and s[i]=='B') s[i+1]='R' ;
  62.                 else if(s[i+2]=='R' and s[i]=='R') s[i+1]='B' ;
  63.                 else if(s[i+2]=='B' and s[i]=='B') s[i+1]='G' ;
  64.                 else if(s[i+2]=='G' and s[i]=='G') s[i+1]='R' ;
  65.            
  66.     }
  67. }
  68. cout << cnt  << nl << s;
  69.  
  70. }
  71.  
  72.  
  73. int main(){
  74.                  IO();    //     files();
  75.                  
  76.        
  77.     int testCase=1;  // one test case
  78.      //  cin >> testCase ;      
  79.  while(testCase--)
  80.         solve();  // my code
  81.        
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement