算法竞赛入门经典(第二版)3-5谜题UVA277
作者:互联网
#include <stdio.h> #include <string.h> #define maxn 5 char a[maxn][maxn]; char b[100]; int flag=0;// int main() { while(1) { int num=0, blank_x,blank_y; while(num<5) { gets(a[num]); num++; } printf("test\n"); int x=0;//int y=0不能在这里定义,原因?? while(x<5) { int key=0,y=0; while(y<5) { if(a[x][y]==' ') { blank_x=x; blank_y=y; key=1; break; } y++; } if(key==1) {break;} x++; } printf("[%d][%d]--\n",blank_x,blank_y); gets(b) ; int len = strlen(b); char temp; for(int i=0;i<len;i++) { switch(b[i]) { case 'A': {a[blank_x][blank_y]=a[blank_x-1][blank_y]; a[blank_x-1][blank_y]=' '; blank_x=blank_x-1;break; } case 'B': {a[blank_x][blank_y]=a[blank_x+1][blank_y]; a[blank_x+1][blank_y]=' '; blank_x=blank_x+1;break; } case 'R': {a[blank_x][blank_y]=a[blank_x][blank_y+1]; a[blank_x][blank_y+1]=' '; blank_y=blank_y+1;break; } case 'L': {a[blank_x][blank_y]=a[blank_x][blank_y-1]; a[blank_x][blank_y-1]=' '; blank_y=blank_y-1;break; } case '0': break; default: flag=1;break; } } if(flag==1) printf("This puzzle has no final configuration.\n"); else { for(int j=0;j<5;j++) { for(int k=0;k<5;k++) { printf(" %c",a[j][k]); } printf("\n"); } } } }
https://vjudge.net/problem/UVA-227
如有错误,欢迎指正
标签:入门,int,谜题,char,num,maxn,blank,UVA277,include 来源: https://www.cnblogs.com/lytuser/p/11704114.html