55pt 求跳
查看原帖
55pt 求跳
1059688
ja_son楼主2024/12/12 22:07
#include <bits/stdc++.h>
using namespace std;

int n,m;
string c[1005];
bool tf=false;

int main() {
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		tf=false;
		int A=1,B=1;
		string b="";
		int tip=0;
		cin>>b;
		b='Z'+b;
		for(int j=1;j<=m;j++){
			if(b[j]=='A'){
				A++;
			}
			else if(b[j]=='B'){
				B++;
			}
			else if(b[j]=='H'){
				tip=j;
				tf=true;
			}
		}
		if(tf){
			for(int z=1;z<=m;z++){
				if(z<A){
					c[i]+='A';
				}
				else if(z+B>=m+2){
					c[i]+='B';
				}
				else if(z==tip){
					c[i]+='H';
					continue;
				}
				else{
					c[i]+='#';
				}
			}
		}
		else{
			if(A>B){
				for(int z=1;z<=m;z++){
					if(z+A>=m+2){
						c[i]+='A';
					}
					else{
						c[i]+='#';
					}
				}
			}
			else if(B>A){
				for(int z=1;z<=m;z++){
					if(z<B){
						c[i]+='B';
					}
					else{
						c[i]+='#';
					}
				}
			}
			else{
				for(int z=1;z<=m;z++){
					c[i]+='#';
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<m;j++){
			if(c[i][j]=='A'){
				if(c[i+1][j]=='A' || c[i-1][j]=='A'){
					cout<<'#';
				}
				else{
					cout<<c[i][j];
				}
			}
			else if(c[i][j]=='B'){
				if(c[i+1][j]=='B' || c[i-1][j]=='B'){
					cout<<'#';
				}
				else{
					cout<<c[i][j];
				}
			}
			else{
				cout<<c[i][j];
			}
		}
		cout<<endl;
	}
	return 0;
}
2024/12/12 22:07
加载中...