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",s...
-
//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.
-
*/
文章来源: gwj1314.blog.csdn.net,作者:小哈里,版权归原作者所有,如需转载,请联系作者。
原文链接:gwj1314.blog.csdn.net/article/details/54846728
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)