UVa 227:Puzzle
2017-02-01 14:10
309 查看
#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; }
相关文章推荐
- uva 227 Puzzle
- Puzzle,ACM/ICPC World Finals 1993,UVa227
- UVA - 227 Puzzle
- Puzzle UVA - 227
- UVA - 227 Puzzle
- UVa227 Puzzle
- Uva 227 - Puzzle (数组和字符串)
- UVa 227 - Puzzle
- UVA227 Puzzle (字符串题)
- UVA - 227 Puzzle
- 习题3-5 UVa 227 Puzzle
- UVa 227 Puzzle (紫书上的题,模拟)
- UVa227 Puzzle
- UVa 227 Puzzle
- UVa 227 Puzzle(习题3-5)
- UVA227 Puzzle
- UVA - 227 Puzzle
- UVA - 227 Puzzle
- Puzzle,UVa227
- UVA - 227 Puzzle