UVA227 puzzle
来源:互联网 发布:java程序开发培训费用 编辑:程序博客网 时间:2024/06/04 20:11
题目:给你一个字母组成的矩阵,其中有一个空位,给你移动的规则(类似平面的一种拼图游戏);
问是否操作合法,合法时输出移动后的结果
#include<stdio.h>char pic[5][5] = {{'T','R','G','S','J'},{'X','D','O','K','I'},{'M',' ','V','L','N'},{'W','P','A','B','E'},{'U','Q','H','C','F'}};int now[2] = {2,1};bool change(char c) {int y = now[0];int x = now[1];switch(c) {case 'A': {//y-1 -> yif(pic[y-1][x]) {pic[y][x] = pic[y-1][x];pic[y-1][x] = ' ';now[0] = y-1;return true;}return false;}case 'B': {//y+1 -> yif(pic[y+1][x]) {pic[y][x] = pic[y+1][x];pic[y+1][x] = ' ';now[0] = y+1;return true;}return false;}case 'L': {//x-1 -> xif(pic[y][x-1]) {pic[y][x] = pic[y][x-1];pic[y][x-1] = ' ';now[1] = x-1;return true;}return false;}case 'R': {//x+1 -> xif(pic[y][x+1]) {pic[y][x] = pic[y][x+1];pic[y][x+1] = ' ';now[1] = x+1;return true;}return false;}}}int main(void) {char c;for(int i=0;i<5;i++) {for(int j=0;j<5;j++) {printf(" %c ",pic[i][j]);}printf("\n");}while(scanf("%c",&c)!=EOF) {if(!change(c)) {printf("This puzzle has no final configuration\n");break;}for(int i=0;i<5;i++) {for(int j=0;j<5;j++) {printf(" %c ",pic[i][j]);}printf("\n");}}}
0 0
- Uva227 - Puzzle
- Uva227.Puzzle
- UVA227-Puzzle
- UVa227 Puzzle
- uva227 - Puzzle
- Puzzle,UVa227
- uva227 - Puzzle
- [UVA227]Puzzle
- UVA227 puzzle
- UVa227 Puzzle
- UVA227 Puzzle
- UVa227 Puzzle
- UVa227:Puzzle
- UVa227 Puzzle
- UVa227 - Puzzle
- Uva227-Puzzle
- uva227 puzzle
- UVa227-Puzzle
- 74、JDK安装与环境变量配置
- leetcode-110. Balanced Binary Tree
- C语言
- 已更改或删除的行值要么不能使该行成为唯一行,要么改变了多个行
- HDU-4599 Dice (概率DP)
- UVA227 puzzle
- AngularJs实现Multipart/form-data 文件的上传
- Leetcode:63. Unique Paths II
- HDU_4069_SquigglySudoku(DancingLinksX精确覆盖+BFS)
- 对Java接口和抽象类的理解
- Python(3)--list和tuple
- 每天一道leetcode题目_(1)
- nginx 版本
- 机器学习基础(六十)—— 凸优化