0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-10 19:38:50 +00:00
OI-codes/S2OJ/17/17.cpp

37 lines
752 B
C++
Raw Normal View History

#include <bits/stdc++.h>
using namespace std;
int t, n, ans;
string s;
bool flag;
char last;
int main() {
cin >> t;
while (t--) {
ans = 0;
cin >> n >> s;
while (!s.empty()) {
flag = false;
for (int i = 1; i < s.size(); i++) {
if (s[i - 1] == s[i]) {
s.erase(s.begin() + i);
flag = true;
break;
}
}
if (!flag) {
s.erase(--s.end());
}
ans++;
last = *s.begin();
while (!s.empty() && last == *s.begin()) {
s.erase(s.begin());
}
}
cout << ans << endl;
}
return 0;
}