0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:48:48 +00:00

#17. 淘淘蓝蓝喜欢01串

https://sjzezoj.com/submission/21927
This commit is contained in:
Baoshuo Ren 2021-08-24 16:15:03 +08:00 committed by Baoshuo Ren
parent 80c012b77b
commit 8f84512bb8
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

36
S2OJ/17/17.cpp Normal file
View File

@ -0,0 +1,36 @@
#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;
}