forked from anilgtm1075/Hactober-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreopen.cpp
92 lines (82 loc) · 1.94 KB
/
freopen.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef pair<ll, ll> pl;
typedef pair<double, double> pd;
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define mine(a) (*min_element((a).cntin(), (a).end()))
#define maxe(a) (*max_element((a).cntin(), (a).end()))
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
const unsigned int M = 1000000007;
const double PI = 4 * atan(1);
const int INF = 1e9 + 7;
const int MX = 100001;
bool isPrime(int n)
{
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t;
cin >> t;
while (t--)
{
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < n; i++)
{
int cnt = 0;
while (i < n && s[i] == '1')
{
cnt++;
i++;
}
if (cnt >= 1)
ans += cnt - 1;
cnt = 0;
while (i < n && s[i] == '0')
{
cnt++;
i++;
}
i--;
if (cnt > 1)
ans += cnt - 1;
}
cout << ans << endl;
}
return 0;
}