一直WA,看了很多帖子,里面说的换行和空格问题已经有注意,能否帮忙DEBUG?
查看原帖
一直WA,看了很多帖子,里面说的换行和空格问题已经有注意,能否帮忙DEBUG?
92805
_RedForest楼主2020/11/10 20:51
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> 
using namespace std;
const int inf=1e1+7;
int posi,posj,cnt,_Upload;
char s[inf][inf],tmp; 
template <typename _TP>
inline void read(_TP &X){
	int w;char ch=0;X=0;
	while(!isdigit(ch)){w=ch=='-';ch=getchar();}
	while(isdigit(ch)){X=(X<<1)+(X<<3)+(ch^48);ch=getchar();}
	X=w?-X:X; 
}
inline void PRINT(){
	if(cnt)cout<<"\n";
	printf("Puzzle #%d:\n",++cnt);
	for(int i=1;i<=5;i++){
		for(int j=1;j<=5;j++){
			if(i==posi && j==posj){
				cout<<"  ";
				continue;
			} 
			cout<<s[i][j]<<" ";
		}
		cout<<"\n";
	}
}
inline void DEBUG(){
	if(cnt)cout<<"\n";
	printf("Puzzle #%d:\n",++cnt);
	cout<<"This puzzle has no final configuration."<<"\n";
	char ch;
	while(ch!='0')ch=getchar(); 
	ch=getchar(); 
}
inline void change(const int x){
	switch(x){
		case 'A':{
			s[posi][posj]=s[--posi][posj];
			break;
		}
		case 'B':{
			s[posi][posj]=s[++posi][posj];
			break;
		}
		case 'L':{
			s[posi][posj]=s[posi][--posj];
			break;
		}
		case 'R':{
			s[posi][posj]=s[posi][++posj];
			break;
		}
	}
}
inline void solve(){
	char x;
	x=getchar();
	while(x!='0'){
		if(x==' ' || x=='\n'){
			x=getchar(); 
			continue;
		} 
		change(x);
		if(posi<=0 || posj<=0 || posi>5 || posj>5){
			DEBUG();
			return ;
		}
		x=getchar();
	}
	getchar();
	PRINT();
}
int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	while(true){
		for(int i=1;i<=5;i++){
			for(int j=1;j<=5;j++){
				tmp=getchar();
				if(tmp==' ' || tmp=='\n'){
					posi=i;posj=j;
				}
				if(tmp=='Z')return 0;
				s[i][j]=tmp;
			}
			if(getchar()=='Z')return 0;
		}
		solve();
	}
	return 0;
} 
2020/11/10 20:51
加载中...