【题目描述】
传送门
【题目分析】
题目的意思很简单,只是输入输出很毒瘤,我一开始用的fgets然后用scanf(" ")吃掉所有的空格和换行,可是这样有可能将迷宫的空格吃掉(例如这个空格恰好在第一行第一列)。
然后改用getchar
需要注意的是最后一个样例最后不能有换行,每两个样例输入之间可能有多余的换行,需要处理掉。
【AC代码】
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<climits>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<cctype>
using namespace std;typedef long long ll;
const int INF=0x3f3f3f3f;
const int MAXN=105;
char mp[10][10];
char cmd,tmp;
int x,y,u,v;
bool flag;
int Case=1;
int first=1;int main()
{//scanf(" ");while(1){char ch=getchar();while(ch=='\n') ch=getchar();if(ch=='Z')break;for(int i=0;i<5;i++){for(int j=0;j<5;j++){while(ch=='\n' && j!=4) ch=getchar();if(ch=='\n') mp[i][j]=' ';else mp[i][j]=ch;if(mp[i][j]==' '){x=i; y=j;}ch=getchar();}}flag=true;while((cmd=getchar())!=EOF && cmd!='0'){if(flag){switch(cmd){case 'A':u=x-1; v=y; break;case 'B':u=x+1; v=y; break;case 'L':u=x; v=y-1; break;case 'R':u=x; v=y+1; break;default:continue;}if(u<0 || u>=5 || v<0 || v>=5){flag=false;continue;}tmp=mp[x][y]; mp[x][y]=mp[u][v]; mp[u][v]=tmp; x=u; y=v;}}if(first) first=0;else printf("\n");printf("Puzzle #%d:\n",Case++);if(!flag){printf("This puzzle has no final configuration.\n");}else{for(int i=0;i<5;i++){for(int j=0;j<4;j++){printf("%c ",mp[i][j]);}printf("%c\n",mp[i][4]);}}}return 0;
}