困难版
2024-05-20 20:19:24
发布于:广东
7阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int countAC(string s) {
int count = 0;
int n = s.length();
for (int i = 0; i < n; ++i) {
if (s[i] == 'A') {
string modified = s;
modified[i] = 'C';
int currCount = 0;
for (int j = 0; j < n - 1; j) {
if (modified[j] == 'A' && modified[j + 1] == 'C') {
currCount;
}
}count = max(count, currCount);
}else if (s[i] == 'C') {
string modified = s;
modified[i] = 'A';
int currCount = 0;
for (int j = 0; j < n - 1; j) {
if (modified[j] == 'A' && modified[j + 1] == 'C') {
currCount;
}
}count = max(count, currCount);
}
}ret urn count;
}int main() {
string s;
cin >> s;
int ans = countAC(s);
cout << ans << endl;
}
这里空空如也
有帮助,赞一个