Guest User

codef

a guest
Sep 29th, 2016
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. #include<string>
  5. #include<map>
  6. using namespace std;
  7. #define boostio ios_base::sync_with_stdio(0);
  8. #define ll long long
  9. #define MAX 30009
  10.  
  11. int main() {
  12. boostio;
  13. string orig;
  14. int n, bs1, bs2, rs1, rs2, c1, c2;
  15. cin >> n;
  16. string s1, s2, new1, new2;
  17.  
  18. cin >> orig;
  19.  
  20. for(int i = 0; i<n; i++){
  21. if(i%2 == 0){s1[i] = 'b'; s2[i] = 'r';}
  22. if(i%2 == 1){s1[i] = 'r'; s2[i] = 'b';}
  23. }
  24.  
  25. for(int i = 0; i<n; i++){
  26. if(orig[i] != s1[i]){new1.push_back(s1[i]);}
  27. if(orig[i] != s2[i]){new2.push_back(s2[i]);}
  28. }
  29.  
  30. bs1 = count(new1.begin(), new1.end(), 'b');
  31. rs1 = count(new1.begin(), new1.end(), 'r');
  32. bs2 = count(new2.begin(), new2.end(), 'b');
  33. rs2 = count(new2.begin(), new2.end(), 'r');
  34.  
  35. c1 = max(bs1,rs1);
  36. c2 = max(bs2,rs2);
  37.  
  38. cout << min(c1,c2);
  39.  
  40. return 0;
  41. }
RAW Paste Data