Files
python/TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202401/6_while.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

37 lines
619 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
/*
测试用例:
5
12321
思路:
1、先看前后是不是存在一样的,这样的优先处理
2、
*/
int cnt = 1;
// 循环写法
void cut(string s) {
while (true) {
int p;
for (p = s.size() - 1; p; p--)
if (s[0] != s[p]) break;
string t;
for (int i = 1; i <= p; i++) t += s[i];
if (t.size())
cnt++, s = t;
else
break;
}
}
int main() {
int n;
string s;
cin >> n >> s;
cut(s);
cout << cnt << endl;
return 0;
}