UVA - 227 Puzzle
2016-07-08 19:12
316 查看
UVA - 227 Puzzle
题目大意。给定一个5X5的格子,给定a~x的英文字母和一个空格,通过ablr移动位置解题思路:二维数组 交换 元素
#include <iostream> #include <stdio.h> using namespace std; int main(){ char c; int n,m; bool t; int s = 1; c = getchar(); while(c != 'z' && c != 'Z'){ t = 1; char a[5][5]; char b[100]; a[0][0] = c; for (int i = 0;i < 5;i++){ for (int j = 0;j < 5; j++){ if (i == 0 && j == 0) continue; a[i][j] = getchar(); } getchar(); } for (int i = 0;b[i-1] != '0';i++) b[i] = getchar(); for (int i = 0;;i++){ for (int j = 0;j < 5;j++) for (int k = 0; k < 5;k++) if (a[j][k] == ' '){ n = j; m = k; } if (b[i] == '0')break; if (b[i] == 'a' || b[i] =='A'){ if (n - 1 < 0){t = 0;break;} a [m] = a[n-1][m]; a[n-1][m] = ' '; } if (b[i] == 'b' || b[i] == 'B'){ if (n + 1 > 4 ){t = 0;break;} a [m] = a[n+1][m]; a[n+1][m] = ' ' ; } if (b[i] == 'l' || b[i] == 'L'){ if (m - 1 < 0){t = 0;break;} a [m] = a [m-1]; a [m-1] = ' '; } if (b[i] == 'r' || b[i] == 'R'){ if (m + 1 > 4){t = 0;break;} a [m] = a [m+1]; a [m+1] = ' '; } } cout<<"Puzzle #"<<s<<":"<<endl; if (t != 0) for (int i = 0; i < 5;i++){ for (int j = 0; j <4 ;j++){ putchar(a[i][j]); cout<<' '; } putchar(a[i][4]); cout<<endl; } else cout<<"This puzzle has no final configuration."<<endl; getchar(); s++; c = getchar(); if (c != 'z' && c != 'Z') cout<<endl; } return 0; }
相关文章推荐
- UVA - 455 Periodic Strings
- Android 防止重复按钮点击
- UVA - 1225 Digit Counting
- 指数取模的方法
- UVA - 1585 Score
- 如何为Linux安装Go语言
- base之basictypes.h基本数据类型 (1下)
- 6步实现laravel图片上传
- python模块之时间模块
- android studio adb 端口被占用http://blog.csdn.net/u012005313/article/details/46964167
- DirectX 因素:了解 XAudio2 中的筛选器
- 2016.7.8模拟赛总结
- js form对象的三种获取方式
- 给Qt生成的exe执行程序添加版本信息
- ViewPager的使用(实现微信左右切换页卡功能)
- wordpress-4.5.3+apache24+mysql5.6+php5.6+windows7x64相关配置
- LaTex 符号
- rsync+inotify-tools实时同步模式
- Android studio项目迁移问题及解决方案
- C语言函数调用过程