Advertisement
jakaria_hossain

codeforce - Diverse Garland

Mar 6th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fastread()(ios_base::sync_with_stdio(false),cin.tie(NULL));
  4. #define ll long long
  5. int main()
  6. {
  7. fastread()
  8. int n,i,r=0;
  9. string s;
  10. cin>>n>>s;
  11. i=1;
  12. while(i<n-1)
  13. {
  14. if(s[i]==s[i-1])
  15. {
  16. r++;
  17.  
  18. if(s[i-1]=='G')
  19. {
  20. s[i]='B';
  21. if(s[i]==s[i+1])s[i]='R';
  22. }
  23. if(s[i-1]=='B')
  24. {
  25. s[i]='R';
  26. if(s[i]==s[i+1])s[i]='G';
  27. }
  28. if(s[i-1]=='R')
  29. {
  30. s[i]='G';
  31. if(s[i]==s[i+1])s[i]='B';
  32. }
  33. }
  34. i++;
  35. }
  36. if(s[i]==s[i-1])
  37. {
  38. r++;
  39.  
  40. if(s[i-1]=='G')
  41. {
  42. s[i]='B';
  43.  
  44. }
  45. if(s[i-1]=='B')
  46. {
  47. s[i]='R';
  48.  
  49. }
  50. if(s[i-1]=='R')
  51. {
  52. s[i]='B';
  53.  
  54. }
  55. }
  56. cout<<r<<endl<<s<<endl;
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement