-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinary Substring
49 lines (36 loc) Β· 1.31 KB
/
Binary Substring
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
#include <bits/stdc++.h>
using namespace std;
int main() {
int tits;cin >> tits;
while (tits--) {
int nnn;cin >> nnn;string s;cin >> s;
vector<int> type(4, 0);
int jjj = 0;
while (jjj < nnn) {
if (s[jjj] == '0' && s[jjj + 1] == '0') {
type[0]++;
} else if (s[jjj] == '0' && s[jjj + 1] == '1') {
type[1]++;
} else if (s[jjj] == '1' && s[jjj + 1] == '1') {
type[2]++;
} else {
type[3]++;
}
jjj = jjj + 2;
}int ans = 0;
if (type[3]) {
ans = 1;
type[3]--;
}
ans = ans + ( 2 * type[0]);
if (type[1]) {
ans = ans+ 2;
}
ans = ans + ( 2 * (type[2]));
if (type[3]) {
ans++;
}
cout << ans << endl;
}
return 0;
}