70pts求条
查看原帖
70pts求条
1048165
SerenityWay楼主2024/11/5 21:10

考试时写的,当时以为可以AC,结果只得了70。WA on #5 #7 #10
代码:

#include <bits/stdc++.h>
using namespace std;
char c[1005][1005]={'x'};
int main(){
	//freopen("explore.in","r",stdin);
	//freopen("explore.out","w",stdout);
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int t;
	cin>>t;
	while(t--){
		int n,m,k,x,y,d,s=1;//s表示步数,由于初始格也算所以初始化为1
		cin>>n>>m>>k>>x>>y>>d;
		for(int i=1;i<=n;i++){//输入
			for(int j=1;j<=m;j++){
				cin>>c[i][j];
			}
		}
		while(k--){
			c[x][y]=',';//标记搜索过
			if(d==0){//判断
				if(c[x][y+1]=='.'){
					y++,s++;
				}else if(c[x][y+1]==','){
					y++;
				}else{
					d=1;
				}
			}else if(d==1){
				if(c[x+1][y]=='.'){
					x++,s++;
				}else if(c[x+1][y]==','){
					x++;
				}else{
					d=2;
				}
			}else if(d==2){
				if(c[x][y-1]=='.'){
					y--,s++;
				}else if(c[x][y-1]==','){
					y--;
				}else{
					d=3;
				}
			}else if(d==3){
				if(c[x-1][y]=='.'){
					x--,s++;
				}else if(c[x-1][y]==','){
					x--;
				}else{
					d=0;
				}
			}
		}
		cout<<s<<"\n";
	}
	return 0;
}

哪个大佬帮忙degug一下让我死心

2024/11/5 21:10
加载中...