題目鏈接 https://vjudge.net/problem/UVA-227
#include<bits/stdc++.h>
using namespace std;
int main()
{
int cot=0;char s;
while(1)
{
fflush(stdin);
char puzzle[10][10]={0};
int x=0,y=0;
int i=0,j=0;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
char ch;
ch=getchar();
while (ch == '\n')
{ch = getchar();}
puzzle[i][j]=ch;
if(ch==' ') {x=j;y=i;}
if(ch=='Z') return 0;
}
}
char ins=0;
int flag=-1;
while(1)
{
ins=getchar();
if(ins=='A')
{
if(y-1<=0) {
flag=1;
break;
}
else
{
swap(puzzle[y][x],puzzle[y-1][x]);
y=y-1;
continue;
}
}
if(ins=='B')
{
if(y+1>=6) {
flag=1;
break;
}
else
{
swap(puzzle[y][x],puzzle[y+1][x]);
y=y+1;
continue;
}
}
if(ins=='L')
{
if(x-1<=0) {
flag=1;
break;
}
else
{
swap(puzzle[y][x],puzzle[y][x-1]);
x=x-1;
continue;
}
}
if(ins=='R')
{
if(x+1>=6) {
flag=1;
break;
}
else
{
swap(puzzle[y][x],puzzle[y][x+1]);
x=x+1;
continue;
}
}
if(ins=='0')
{
flag=0;
break;
}
}
cot++;
if(cot != 1)
cout<<endl ;
cout << "Puzzle #" << cot <<":" << endl ;
if(!flag)
for(int i = 1; i < 6; i++) {
for(int j = 1; j < 6; j++) {
if(j != 1) cout << ' ' ;
cout << puzzle[i][j] ;
}
cout << endl ;
}
else
{
cout << "This puzzle has no final configuration." << endl ;
}
}
return 0;
}
這個是input
TRGSJ
XDOKI
M VLN
WPABE
UQHCF
ARRBBL0
ABCDE
FGHIJ
KLMNO
PQRS
TUVWX
AAA
LLLL0
ABCDE
FGHIJ
KLMNO
PQRS
TUVWX
AAAAABBRRRLL0
Z
按照樣例輸出都對 為什么還是WA 搞了一天了還是沒找出來哪里有問題...

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/223356.html
標籤:新手樂園
上一篇:幫忙看看
下一篇:優先演算法 C語言
