UVA - 227 Puzzle
来源:互联网 发布:淘宝网黑盘羊沉香好吗 编辑:程序博客网 时间:2024/06/04 18:16
个人觉得这个题很简单,只是刚开始可能各种格式和字符读取问题有点绕,下面是代码:
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char matrix[5][5];int main(){ int c; int kase = 0; while((c=getchar())) { if(c=='Z')return 0; ungetc(c,stdin); int bi,bj; int error = 0; for(int i=0; i<5; i++) { for(int j=0; j<5; j++) { matrix[i][j] = getchar(); if(matrix[i][j]==' '){bi=i;bj=j;} } getchar(); } while((c=getchar())!='0') { if(c==' '||c=='\t'||c=='\n')continue; if(c=='A') { if(bi==0){error=1;break;} swap(matrix[bi][bj],matrix[bi-1][bj]); bi--; }else if(c=='B') { if(bi==4){error=1;break;} swap(matrix[bi+1][bj],matrix[bi][bj]); bi++; }else if(c=='L') { if(bj==0){error=1;break;} swap(matrix[bi][bj],matrix[bi][bj-1]); bj--; }else if(c=='R') { if(bj==4){error=1;break;} swap(matrix[bi][bj],matrix[bi][bj+1]); bj++; } } if(error){while((c=getchar())!='0');} if(getchar()=='Z')break; kase++; if(kase>1)putchar('\n'); printf("Puzzle #%d:\n",kase); if(error)printf("This puzzle has no final configuration.\n"); else for(int i=0; i<5; i++) { for(int j=0; j<5; j++) { putchar(matrix[i][j]); if(j<4)putchar(' '); } putchar('\n'); } } return 0;}
0 0
- 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
- UVa 227 Puzzle
- UVA - 227 Puzzle
- Uva - 227 - Puzzle
- UVA - 227 Puzzle
- UVa 227 Puzzle
- UVA 227 Puzzle
- UVa 227 - Puzzle
- UVa 227 Puzzle
- unique_ptr
- SSL通信过程抓包分析
- Spring定义的7种不同的事务传播行为
- java基础之多线程
- 1003. Emergency (25)
- UVA - 227 Puzzle
- GitHub Hacking
- Swift - 元组的用法
- OFBiz安装注意事项:不要启动Tomcat
- shared_ptr
- 【转自网上,分享更多人看到】创建符号链接 “asm”: 不支持的操作
- Android decode
- JAVA+jni 包名或方法名中含有下划线(_)的解决方法
- 删除分区表students子分区sex_male中年龄大于30岁的记录