函数
2023-12-30 15:19:07
发布于:广东
6阅读
0回复
0点赞
#include <iostream>
using namespace std;
int countAC(string s){
int count = 0;
int n = s.size();
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);
}
}
return count;
}
int main(){
string s;
cin >> s;
int result = countAC(s);
cout << result;
return 0;
}
这里空空如也
有帮助,赞一个