0分求助
  • 板块P1189 SEARCH
  • 楼主Ch35
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/10/28 21:02
  • 上次更新2023/10/27 05:20:22
查看原帖
0分求助
672360
Ch35楼主2022/10/28 21:02
 #include<bits/stdc++.h>
using namespace std;
int n,m,t,cnt=0;
char a[100][100];
string s;
queue<int>x;
queue<int>y;
int main(){
	//freopen("dragracing.in","r",stdin);
	//freopen("dragracing.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
			if(a[i][j]=='*')x.push(i),y.push(j),a[i][j]='.';
		}
	}
	scanf("%d",&t);
	while(t--){
		int xx=x.front(),yy=y.front();
		cin>>s;
		if(t==1){
			if(s=="EAST"){
			while(yy++<=m&&a[xx][yy]!='X')x.push(xx),y.push(yy),cnt++;
			}
			if(s=="SOUTH"){
				while(xx++<=n&&a[xx][yy]!='X')x.push(xx),y.push(yy),cnt++;
			}
			if(s=="WEST"){
				while(yy--<=n&&a[xx][yy]!='X')x.push(xx),y.push(yy),cnt++;
			}
			if(s=="NORTH"){
				while(xx--<=n&&a[xx][yy]!='X')x.push(xx),y.push(yy),cnt++;
			}
		}
		else{
			if(s=="EAST"){
				while(yy++<=m&&a[xx][yy]!='X')x.push(xx),y.push(yy);
			}
			if(s=="SOUTH"){
				while(xx++<=n&&a[xx][yy]!='X')x.push(xx),y.push(yy);
			}
			if(s=="WEST"){
				while(yy--<=n&&a[xx][yy]!='X')x.push(xx),y.push(yy);
			}
			if(s=="NORTH"){
				while(xx--<=n&&a[xx][yy]!='X')x.push(xx),y.push(yy);
			}
		}
		
		x.pop(),y.pop();
	}
	cnt-=2;
	while(cnt--){
		
		a[x.front()][y.front()]='*',x.pop(),y.pop();
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<a[i][j];
		}
		cout<<endl;
	}
	return 0;
}

https://www.luogu.com.cn/record/91211604

2022/10/28 21:02
加载中...