码风优良,求调
查看原帖
码风优良,求调
1032391
ICE__LX楼主2025/2/7 09:43

rt,对拍了好久对不出来。。

#include<bits/stdc++.h>
using namespace std;
#define I_love_Foccarus return
#define in(a) a=read()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define deap(i,a,b) for(int i=b;i>=a;i--)
#define pii pair<int,int>
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pd(a) push_back(a)
//#define int long long
const int N = 2e5 + 5;
const int inf = INT_MAX;
inline int read(){
	int ch=getchar(),f=1,x=0;
	while('9'<ch||ch<'0'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while('0'<=ch&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
  return x*f;
}
void fast() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}
signed main(){
	//fast();
	int t;
	in(t);
	while(t--){
		string a , b;
		cin>>a;
		b = a;
		reverse(b.begin() , b.end());
		int ans1 = 0 , ans2 = 0, len = a.size() , h = 0;
		for(int i = 1 ; i < len ; i++){
			if(a[i - 1] == 'A' && a[i] == 'B'){
				ans1+=h;
				ans1++;
				a[i - 1] = 'B' , a[i] = 'C';
			}
			else if(a[i - 1] == 'B' && a[i] == 'A'){
				ans1++;
				a[i - 1] = 'C' , a[i] = 'B';
			}
			if(a[i - 1] == 'A') h++;
			else h = 0;
		} 
		 h = 0;
		for(int i = 1 ; i < len ; i++){
			if(b[i - 1] == 'A' && b[i] == 'B'){
				ans2+=h;
				ans2++;
				b[i - 1] = 'B' , b[i] = 'C';
			}
			else if(b[i - 1] == 'B' && b[i] == 'A'){
				ans2++;
				b[i - 1] = 'C' , b[i] = 'B';
			}
			if(b[i - 1] == 'A') h++;
			else h = 0;
		} 
		cout<<max(ans1,ans2)<<'\n';
	}
	I_love_Foccarus 0;
}


2025/2/7 09:43
加载中...