UVa227

//UVa227 - Puzzle
#include<stdio.h>
void swap(char *a, char *b){
	char t = *a; *a = *b; *b = t;
}
int main(){
	//freopen("date.in","r",stdin);
	//freopen("date.out","w",stdout);
	char s[6][6] = {0}, n;
	int x1, y1, x2, y2;
	int i, j, is = 0;
	for(i = 0; i<5; i++){
		for(j = 0; j<5; j++){
			s[i][j] = getchar();
			if(s[i][j] == ' ')x1 = x2 = i, y1 = y2 = j;
		}
		getchar();
		//printf("%s
",s[i]);
	}
	while(scanf("%c",&n) && n != '0'){
		switch(n){
			case'A': x2 -= 1; break;
			case'B': x2 += 1; break;
			case'L': y2 -= 1; break;
			case'R': y2 += 1; break;
			default: is = 1;
		}
		swap(&s[x1][y1],&s[x2][y2]);
		x1 = x2; y1 = y2;
	}
	if(is) printf("This puzzle has no final configuration.
");
	else{
		for(i = 0; i<5; i++)
			printf("%s
",s[i]);
	}
	return 0;
}
/*
Sample Input:
TRGSJ
XDOKI
M VLN
WPABE
UQHCF
ARRBBL0
ABCDE
FGHIJ
KLMNO
PQRS 
TUVWX
AAA
LLLL0
ABCDE
FGHIJ
KLMNO
PQRS 
TUVWX
AAAAABBRRRLL0
Z
------------------------
Sample Output:
Puzzle #1:
T R G S J
X O K L I
M D V B N
W P   A E
U Q H C F

Puzzle #2:
  A B C D
F G H I E
K L M N J
P Q R S O
T U V W X

Puzzle #3:
This puzzle has no final configuration.
*/

原文地址:https://www.cnblogs.com/gwj1314/p/9444932.html