#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
//ios::sync_with_stdio(false);
char a[10][10];
char tma[10];
int main()
{
int t = 1;
//freopen("out.txt","w",stdout);
//freopen("in.txt","r",stdin);
while(1)
{
gets(tma);
if(strlen(tma) == 1 && tma[0] == 'Z'){
break;
}
for(int i = 0;i < 5;i++)
{
if(tma[i] == '\0')
tma[i] = ' ';
a[0][i] = tma[i];
}
for(int i = 1;i < 5;i++)
{
gets(tma);
for(int j =0 ;j < 5;j++)
{
if(tma[j] == '\0')
tma[j] = ' ';
a[i][j] = tma[j];
}
}
int sx,sy;
for(int i = 0;i < 5;i++)
{
for(int j = 0;j < 5;j++)
{
if(a[i][j] == ' '){
sx = i;
sy = j;
}
}
}
char op;
int flag = 0;
while(op = getchar(),op != '0')
{
int nx = sx ,ny= sy;
switch (op){
case 'A':
{
nx --;
break;
}
case 'B':
{
nx ++;
break;
}
case 'R':
{
ny ++;
break;
}
case 'L':
{
ny --;
break;
}
default:
{
continue;
}
}
if(flag) continue;
if(nx < 0 || nx >= 5 || ny < 0 || ny >= 5){
flag = 1;
continue;
}
else{
swap(a[sx][sy],a[nx][ny]);
sx = nx;
sy = ny;
}
}
if(t != 1)
printf("\n");
printf("Puzzle #%d:\n",t++);
if(flag){
printf("This puzzle has no final configuration.\n");
}
else
for(int i = 0;i < 5;i++)
{
for(int j = 0;j < 5;j++)
{
if(j!= 0)
printf(" ");
printf("%c",a[i][j]);
}
printf("\n");
}
getchar();
}
return 0;
}
长期因为在输出最后的提示串的时候发现自己少复制了一个‘.’已经不是一次啦!真是错都不知道自己是哪里错了!水!!!
uva 227 模拟题
最新推荐文章于 2021-11-01 15:35:13 发布