UVa227 谜题 Puzzle
来源:互联网 发布:淘宝买家版下载 编辑:程序博客网 时间:2024/06/06 18:06
题目描述:
题目分析:
题目本身很简单,模拟就能过,但是要注意这里的输入输出格式,极容易WA和RE
AC代码:
/*by_superxdtime_2016年9月22日 19:38:40*/#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<cstdlib>#include<algorithm>#define LIM (sx>=0&&sx<=4&&sy>=0&&sy<=4)using namespace std;char map[5][5];int sx,sy,x,y;//记录空白处的位置int cnt;//第cnt组数据char step[1005];//记录处理的次序char sh,ch;int num;//记录step数组的长度int main(){ cnt=1; while(gets(map[0])) { if(map[0][0]=='Z') break; for(int i=1;i<=4;i++) { gets(map[i]); } for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { if(map[i][j]==' ') { sx=i; sy=j; break; } } } num=0; while(ch=getchar()) { step[++num]=ch; if(ch=='0') break; } int k; for(k=1;k<num;k++) { if(step[k]=='A') { sx-=1; if(LIM) { map[sx+1][sy]=map[sx][sy]; map[sx][sy]=' '; } else { break; } } else if(step[k]=='B') { sx+=1; if(LIM) { map[sx-1][sy]=map[sx][sy]; map[sx][sy]=' '; } else { break; } } else if(step[k]=='L') { sy-=1; if(LIM) { map[sx][sy+1]=map[sx][sy]; map[sx][sy]=' '; } else { break; } } else if(step[k]=='R') { sy+=1; if(LIM) { map[sx][sy-1]=map[sx][sy]; map[sx][sy]=' '; } else { break; } } } if(cnt!=1) printf("\n"); printf("Puzzle #%d:\n",cnt++); if(k==num) { for(int i=0;i<=4;i++) { for(int j=0;j<=3;j++) { printf("%c ",map[i][j]); } printf("%c\n",map[i][4]); } } else { printf("This puzzle has no final configuration.\n"); } getchar(); } return 0;}
0 0
- UVa227 谜题 Puzzle
- 谜题(Puzzle UVa227)
- Uva227-Puzzle-谜题
- 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
- [Android | 小代码] 天气预报 简易Demo json解析数组+对象 Gson+Volley简单使用
- DOM
- 谈谈深度学习中的 Batch_Size
- JPush的使用简单范例
- kali linux nc基本教程
- UVa227 谜题 Puzzle
- 希尔排序
- opencv 学习笔记第一天
- android 导入第三方包出错
- 颠倒的价牌
- 百度面试总结
- [OpenGL ES 02]OpenGL ES渲染管线与着色器
- “ 鸡尾酒会问题”(cocktail party problem)
- DBUtils框架的应用(小巧的数据库连接工具)