求助P2033
查看原帖
求助P2033
307603
_cmh楼主2020/7/11 11:06

蒟蒻调了一天了,脑子都烧废了

求大佬帮助

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdlib>
using namespace std;
int x,nowx,nowy,now;
char a[9][9];
int dx[5]={0,0,-1,0,1};
int dy[5]={0,-1,0,1,0};
string s,s2;
int pd1(int px,int py){
	if(a[px][py]=='^') return 1;
	else if(a[px][py]=='<') return 2;
	else if(a[px][py]=='v') return 3;
	else if(a[px][py]=='>') return 4;
	else return 0;
}
char pd2(int n){
	if(n==1) return '^';
	if(n==2) return '<';
	if(n==3) return 'v';
	if(n==4) return '>';
}
int turn(string ss){
	if(ss=="left") return 1;
	else if(ss=="right") return -1;
	else if(ss=="back") return 2;
}
void fd(){
	int tot=nowx;
	while(tot>=1&&a[tot][nowy]!='.') tot--;
	for(int j=tot;j<=nowx;j++) a[j][nowy]=a[j+1][nowy];
	a[nowx+1][nowy]='.';
}
void lt(){
	int tot=nowy;
	while(tot>=1&&a[nowx][tot]!='.') tot--;
	for(int j=tot;j<=nowy;j++) a[nowy][j]=a[nowy][j+1];
	a[nowx][nowy+1]='.';
}
void bk(){
	int tot=nowx;
	while(tot<=8&&a[tot][nowy]!='.') tot++;
	for(int j=tot;j>=nowx;j--) a[j][nowy]=a[j-1][nowy];
	a[nowx-1][nowy]='.';
}
void rt(){
	int tot=nowy;
	while(tot<=8&&a[nowx][tot]!='.') tot++;
	for(int j=tot;j>=nowy;j--) a[nowy][j]=a[nowy][j-1];
	a[nowx][nowy-1]='.';
}
void move(int n){
	int ccf=pd2(a[nowx][nowy]);
	for(int i=1;i<=n;i++){
		int nx=nowx+dx[ccf];
		int ny=nowy+dy[ccf];
		if(nx>8||nx<1||ny>8||ny<1) return;
		nowx=nx;nowy=ny;
		if(now==1) fd();
		if(now==2) lt();
		if(now==3) bk();
		if(now==4) rt();
	}
}
void out(){
	for(int i=1;i<=8;i++,cout<<endl)
		for(int j=1;j<=8;j++)
			cout<<a[i][j];
}
int main(){
	for(int i=1;i<=8;i++)
		for(int j=1;j<=8;j++){
			cin>>a[i][j];
			if(pd1(i,j)!=0) nowx=i,nowy=j,now=pd1(i,j);
		}
	while(cin>>s){
		if(s=="#"){
			out();
			return 0;
		}
		if(s=="move") cin>>x,move(x);
		if(s=="turn"){
			cin>>s2;
			now+=turn(s2);
			if(now==0) now=4;
			if(now==5) now=1;
			a[nowx][nowy]=pd2(now);
		}
		//cout<<endl;
		//out();
		//cout<<endl;
	}
    return 0;
}
2020/7/11 11:06
加载中...