-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfb1a.cpp
57 lines (45 loc) · 1012 Bytes
/
fb1a.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
const int INF = 1e9;
void solve() {
int n;
cin >> n;
vector<char> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
int best_o = 0;
int best_x = 0;
for (int i = 0; i < n; i++) {
int old_o = best_o;
int old_x = best_x;
char c = a[i];
if (c == 'F') {
best_o = min(old_o, old_x + 1);
best_x = min(old_x, old_o + 1);
};
if (c == 'O') {
best_o = min(old_o, old_x + 1);
best_x = INF;
}
if (c == 'X') {
best_x = min(old_x, old_o + 1);
best_o = INF;
}
}
cout << min(best_o, best_x) << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
cout << "Case #" << i << ": ";
solve();
}
return 0;
}