紫书章三习题5——UVA 227 Puzzle
来源:互联网 发布:sql server清空数据库 编辑:程序博客网 时间:2024/05/29 19:32
这道题,主要学习了
1.怎么将代码写的好看(简洁),之前 都是冗长冗长的,能不动脑子就不动脑子。switch,?:
2.freopen(“D:\input.txt”,”r”,stdin)的运用,提交的时候一定要加\
3.fgets(数组,maxn,stdin)
输入到数组中,长度为不超过maxn-1,然后在末尾加上\0,所以不会超空间。fgets是读取完整的一行,读到回车符截止,然后‘\n’也是这个数组中最后一个有效字符
4.这道题很容易卡输出PE,因为题目中说了,每两个结果之间要有有个空行,所以最后一个是没有空行的。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define maxn 100005char s[10][10];char op[100005];int f[10]={-1,1,0,0};int x1[10]={0,0,-1,1};int main(){ // freopen("D:\\input.txt","r",stdin); int temp=0; while(fgets(s[0],10,stdin)&&s[0][0]!='Z') { for(int i=1;i<5;i++) fgets(s[i],10,stdin); int x=0,y=0; for(int i=0;i<5;i++) for(int j=0;j<5;j++) { if(s[i][j]==' '||s[i][j]=='\n') { x=i;y=j; break; } } temp++; if(temp!=1) printf("\n"); int stop=0,flag=0; char c; while((c=getchar())!=EOF&&c!='0') { int stop=0; switch(c) { case 'A': {stop=0;break;} case 'B': {stop=1;break;} case 'L' : {stop=2;break;} case 'R': {stop=3;break;} default: continue; } int x11=x,y1=y; x+=f[stop],y+=x1[stop]; s[x11][y1]=s[x][y]; if(x<0||y<0||x>=5||y>=5) flag=1; } printf("Puzzle #%d:\n",temp); if(flag==1) printf("This puzzle has no final configuration.\n"); else { s[x][y]=' '; for(int i=0;i<5;i++) { for(int j=0;j<5;j++) j==0? printf("%c",s[i][j]):printf(" %c",s[i][j]); printf("\n"); } } getchar();//因为‘0’后面还有一个换行符 } return 0;}
0 0
- 紫书章三习题5——UVA 227 Puzzle
- 【习题3-5】 UVA - 227 Puzzle
- 习题3-5 UVa 227 Puzzle
- UVa 227 Puzzle(习题3-5)
- 小紫书 习题 3-5(UVA 227) 谜题(Puzzle)
- Problem 015 —— UVa 227 Puzzle
- 习题 3-5 谜题 Puzzle (World Finals 1993) UVa 227
- 习题3-5 puzzle
- 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
- C++第1次实验-项目2
- JavaSE 学习参考:方法的基本概念
- 移动互联网APP测试点
- 将磁盘文本数据导入数据表
- 深拷贝 浅拷贝 内存零拷贝
- 紫书章三习题5——UVA 227 Puzzle
- CUDA 编程 之 配置cache函数
- Intel TBB简介及在Windows7 VS2013上源码的编译过程
- HDU 6015 Skip the Class【BestCoder Round #92】map
- 201403第一届CCF第二题 窗口
- Combination Sum
- A2DP & AVRCP,蓝牙音频协议的兄弟组合(1)
- 算法相关——Java排序算法之选择排序(六)
- Ubuntu搭建开发openchannelssd的qemu的虚拟机