uva 227 Puzzle
来源:互联网 发布:峡山淘宝运营培训 编辑:程序博客网 时间:2024/05/18 00:12
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> using namespace std; char maps[5][7]; char cmd[1001]; int main() { int cases = 0; while (gets(maps[0])) { if (maps[0][0] == 'Z') break; for (int i = 1 ; i < 5 ; ++ i) gets(maps[i]); int b_x = 0,b_y = 0; for (int i = 0 ; i < 5 ; ++ i) for (int j = 0 ; j < 5 ; ++ j) if (maps[i][j] == ' ') { b_x = i;b_y = j; break; } int count = 0; while (~scanf("%c",&cmd[count])) if (cmd[count] != '0') count ++; else break; cmd[count] = 0;getchar(); int flag = 0,x = b_x,y = b_y; for (int i = 0 ; cmd[i] ; ++ i) { switch(cmd[i]) { case 'A': x = b_x-1;y = b_y; break; case 'B': x = b_x+1;y = b_y; break; case 'L': x = b_x;y = b_y-1; break; case 'R': x = b_x;y = b_y+1; break; } if (x < 0 || x > 4 || y < 0 || y > 4) { flag = 1;break; }else { maps[b_x][b_y] = maps[x][y]; maps[x][y] = ' '; b_x = x; b_y = y; } } if (cases ++) printf("\n"); printf("Puzzle #%d:\n",cases); if (flag) printf("This puzzle has no final configuration.\n"); else { for (int i = 0 ; i < 5 ; ++ i) { printf("%c",maps[i][0]); for (int j = 1 ; j < 5 ; ++ j) printf(" %c",maps[i][j]); printf("\n"); } } } return 0; }
0 0
- UVa 227 - Puzzle
- UVa 227 - Puzzle
- Uva-227-Puzzle
- UVa 227 Puzzle
- UVA - 227 Puzzle
- Uva-227 - Puzzle-AC
- UVa 227 - Puzzle
- UVa-227 - Puzzle
- 【Uva 227】 Puzzle
- UVa 227 - Puzzle
- UVa 227 Puzzle
- UVA - 227 Puzzle
- Uva - 227 - Puzzle
- UVA - 227 Puzzle
- UVa 227 Puzzle
- UVA 227 Puzzle
- UVa 227 - Puzzle
- UVa 227 Puzzle
- 开车
- uva 1368 DNA Consensus String
- 宏定义SIG_DFL及SIG_IGN
- EA类图与代码同步
- 双向链表
- uva 227 Puzzle
- 工程设计人员VB开发注意几个问题
- AndroidStudio打包及引用aar - Android
- 自定义Dialog
- MFC-抓取网页源码
- uva 455 Periodic Strings
- matrix(No.1)operations
- 模仿QQ聊天
- 分析exec*函数对应的系统调用处理过程