UVa 227:Puzzle
来源:互联网 发布:php两年工作经验简历 编辑:程序博客网 时间:2024/05/21 10:34
#include <stdio.h>void swap(char* a, char* b){ char t = *a; *a = *b; *b = t;}int main(){ char puzzle[5][6], ch; char* e = "This puzzle has no final configuration."; int ct = 0; while(1) { gets(puzzle[0]); if('Z' == puzzle[0][0]) break; gets(puzzle[1]); gets(puzzle[2]); gets(puzzle[3]); gets(puzzle[4]); int x, y; for(x = 0; x < 5; ++x) { int flag = 0; for(y = 0; y < 5; ++y) if(' ' == puzzle[x][y]) { flag = 1; break; } if(flag) break; } if(ct) putchar('\n'); printf("Puzzle #%d:\n", ++ct); int error = 0; while((ch = getchar()) != '0') { if(error) continue; if('A' == ch) { if(x - 1 >= 0) { swap(&puzzle[x][y], &puzzle[x-1][y]); --x; continue; } else { printf("%s\n", e); error = 1; continue; } } if('B' == ch) { if(x + 1 < 5) { swap(&puzzle[x][y], &puzzle[x+1][y]); ++x; continue; } else { printf("%s\n", e); error = 1; continue; } } if('L' == ch) { if(y - 1 >= 0) { swap(&puzzle[x][y], &puzzle[x][y-1]); --y; continue; } else { printf("%s\n", e); error = 1; continue; } } if('R' == ch) { if(y + 1 < 5) { swap(&puzzle[x][y], &puzzle[x][y+1]); ++y; continue; } else { printf("%s\n", e); error = 1; continue; } } } if(!error) { for(x = 0; x < 5; ++x) { for(y = 0; y < 4; ++y) printf("%c ", puzzle[x][y]); printf("%c\n", puzzle[x][4]); } } while(getchar() != '\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
- SDWebImage源码解读之干货大总结
- 前m大的数
- 大学
- 上升子序列
- 【小作品】新版微博个人主页(LESS+切图)
- UVa 227:Puzzle
- HTML如何把文件上传到指定目录下
- flexbox布局text文本单行显示多余省略号代替
- 自定义Android Toast
- 337. House Robber III**
- 做了几个Firefox的主题
- 通过两个点的经纬度计算距离
- SHOW SLAVE STATUS 详解
- 一月英语总结