-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2188B.cpp
More file actions
46 lines (39 loc) · 753 Bytes
/
2188B.cpp
File metadata and controls
46 lines (39 loc) · 753 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
46
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
void solve() {
ll n;
string s;
cin>>n;
cin>>s;
ll count = 0;
for(char c : s){
if(c == '1'){
count++;
}
}
for(ll i = 1 ; i < n ;i++){
if(s[i] == '1' && s[i + 1] == '1' || s[i] == '0' && s[i + 1] == '1'){
count++;
}
}
cout<<count<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t ;
cin >> t;
while (t--) {
solve();
}
return 0;
}