Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define ull unsigned ll
- #define nl "\n"
- #define sz(x) x.size()
- #define NumOfDigit(w) log10(w) + 1
- #define fill(arr, val) memset(arr, val , sizeof(arr))
- #define PI 3.141592654
- #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define fi first
- #define se second
- #define cin(v) for (auto&i:v) cin >> i;
- #define cout(v) for (auto&i:v) cout << i << " ";
- #define fixed(n) fixed << setprecision(n)
- #define MOD 1000000007
- void IO(){
- ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- }
- void files(){
- //freopen("filename.in" , "r" ,stdin);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
- #endif
- }
- bool prime(ll n){
- if(n==2 || n==3) return true;
- if(n<2 || n%2==0 ) return false;
- for(int i=3;i<=sqrt(n);i+=2) if(n%i==0) return false;
- return true;
- }
- bool cmp(pair < string , int > p1 , pair < string , int > p2){
- return p1.second > p2.second;
- }
- void solve(){
- int n; cin >> n;
- string s; cin >> s;
- int cnt=0;
- for(int i=0;i<n-1;i++){
- if(s[i]==s[i+1]){
- cnt++;
- if(i == n-2 ){
- if(s[i]=='R') s[i+1]='G';
- else if(s[i]=='G') s[i+1]='R';
- else s[i+1]='R';
- break;
- }
- if(s[i+2]=='B' and s[i+1]=='R') s[i+1]='G' ;
- else if(s[i+2]=='R' and s[i]=='B') s[i+1]='G' ;
- else if(s[i+2]=='G' and s[i]=='R') s[i+1]='B' ;
- else if(s[i+2]=='R' and s[i]=='G') s[i+1]='B' ;
- else if(s[i+2]=='B' and s[i]=='G') s[i+1]='R' ;
- else if(s[i+2]=='G' and s[i]=='B') s[i+1]='R' ;
- else if(s[i+2]=='R' and s[i]=='R') s[i+1]='B' ;
- else if(s[i+2]=='B' and s[i]=='B') s[i+1]='G' ;
- else if(s[i+2]=='G' and s[i]=='G') s[i+1]='R' ;
- }
- }
- cout << cnt << nl << s;
- }
- int main(){
- IO(); // files();
- int testCase=1; // one test case
- // cin >> testCase ;
- while(testCase--)
- solve(); // my code
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement