不知道第几周的题了
writer,coder,jcer all
U540458 -a-b-c-
今天终于又轮到晓莱出题目了。
题目规则非常的简单,直接给定一个只由, , 构成的字符串。
晓莱希望在字符串上执行以下操作:
选择一个连续的 的子字符串,如果该字符串是 ABC 将其替换为 BCA。
请你输出最多可以执行多少次操作。
输入格式
输入一个字符串。
一共就-种情况 1.
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 5;
const int M = 1e6 + 5;
const int INF = 1e18;
int n;
string s;
signed main(){
// freopen("T1.in", "r", stdin);
// freopen("T1.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s;
n = s.size();
s = " " + s;
int ans = 0,x = 0;
for(int i = 1; i <= n; i++){
if(s[i] == 'A'){
int j = i,y = 0;
while(j <= n && s[j] == 'A'){
j++;
x++;
}
while(j + 1 <= n && s[j] == 'B' && s[j + 1] == 'C'){
j += 2;
y++;
}
ans += x * y;
i = j - 1;
}else{
x = 0;
}
}
cout << ans << "\n";
return 0;
}