mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 20:48:48 +00:00
parent
80c012b77b
commit
8f84512bb8
36
S2OJ/17/17.cpp
Normal file
36
S2OJ/17/17.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user