#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 2e5 + 10;
char s[N];
void solve()
{
int n;
cin >> n >> s + 1;
int sum0 = 0, sum1 = 0;
for (int i = 1; i <= n; i ++ )
{
if (s[i] == '1' && s[i + 1] == '1')
sum0++;
if (s[i] == '0' && s[i + 1] == '0')
sum1++;
}
cout << max(sum1, sum0) << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
https://codeforces.com/problemset/problem/1433/D题
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
const int N = 1e5 + 10;
int a[N];
map<int, int> mp;
vector<pair<int, int>> v;
void solve()
{
mp.clear();
int n;
cin >> n;
int b = -1, c = -1;
int id;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
mp[i] = a[i];
if (i == 1)
b = a[i];
else if (i >= 2 && a[i] != b)
{
c = a[i];
id = i;
}
}
if (c == -1)
{
cout << "NO" << endl;
return;
}
else
{
cout << "YES" << endl;
for (int i = 2; i <= n; i++)
{
if (mp[i] != b)
v.push_back({1, i});
else if (id != i && mp[i] == b)
v.push_back({id, i});
}
for (int i = 0; i < v.size(); i++)
{
cout << v[i].first << ' ' << v[i].second << endl;
}
v.clear();
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}