UVa227 - Puzzle

//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\n",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.\n");
	else{
		for(i = 0; i<5; i++)
			printf("%s\n",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.
*/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小哈里

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值