-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf.cpp
More file actions
45 lines (43 loc) · 853 Bytes
/
cf.cpp
File metadata and controls
45 lines (43 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <utility>
#include <stack>
#include <cstring>
using namespace std;
char dict[2] = { 'r','b'};
void change(char &c) {
if (c == dict[0]) c = dict[1];
else c = dict[0];
}
int count(const string &s, const char &start) {
int len = s.length();
int ans = 0;
char cur = start;
int countOfBlack = 0;
int countOfRed = 0;
for (int i = 0; i<len; ++i) {
if (s[i] != cur) {
if (s[i] == 'r') ++countOfRed;
else ++countOfBlack;
}
change(cur);
}
return max(countOfBlack, countOfRed);
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
int c[2];
memset(c, 0, sizeof(c));
for (int i = 0; i<2; ++i) {
c[i] = count(s, dict[i]);
}
cout << min(c[0], c[1]) << endl;
return 0;
}