哪里错了,大佬们帮忙看下QAQ
查看原帖
哪里错了,大佬们帮忙看下QAQ
260978
Day_Dreamer_H楼主2020/7/2 16:36
#include<bits/stdc++.h>
using namespace std;
char a[15][15];//地图 
int runx[4] = {-1,0,1,0};
int runy[4] = {0,1,0,-1};
//四方向,因为是顺时针,所以顺序是上右下左 
int main(){
	for(int i = 0;i<=11;i++){
		for(int j = 0;j<=11;j++){
			a[i][j] = '*';
		}
	}//直接把整个都赋值成'*',之后输入会把里面的东西覆盖,留下边缘 
	int jx,jy,jmove_plan = 0;//john的坐标和移动方法 
	int cx,cy,cmove_plan = 0;//奶牛的坐标和移动方法 
	int res = 0;//要走几分钟 
	for(int i = 1;i<=10;i++){
		for(int j = 1;j<=10;j++){
			a[i][j] = getchar();
			if(a[i][j] == 'F'){
				jx = i;
				jy = j;
				a[i][j] = '.';
			}
			if(a[i][j] == 'C'){
				cx = i;
				cy = j;
				a[i][j] = '.';
			}
		}
		getchar();//把回车读掉 
	}
	while(jx != cx||jy != cy){//只要没有相遇就继续下去 
		if(res>=1000000){//走的次数太多,肯定重复 
			cout<<0;
			return 0;
		}
		int nowjx = jx+runx[jmove_plan],nowjy = jy+runy[jmove_plan];
		//现在john的坐标 
		int nowcx = cx+runx[cmove_plan],nowcy = cy+runy[cmove_plan];
		//现在奶牛的坐标 
		if(a[nowjx][nowjy]!='.'){//前面不能走,只能花一分钟转弯 
			jmove_plan++;
			jmove_plan%=4;
		}else{//反之向之前的方向走一格 
			jx = nowjx;
	   		jy = nowjy;
		}
		if(a[nowcx][nowcy]!='.'){
			cmove_plan++;
			cmove_plan%=4;
		}else{
			cx = nowcx;
	   		cy = nowcy;
		}//同理 
	   	res++;//一分钟走完了,分钟数++ 
	}
	cout<<res;
	return 0;
} 
2020/7/2 16:36
加载中...