3.5 Puzzle UVA227
来源:互联网 发布:js向html传值 编辑:程序博客网 时间:2024/06/11 14:30
题目链接:点击打开链接
我当时取得函数名真奇葩
初始化二维数组我怎么会用getchar的,,,,难道是防空格吗,怎么着还有gets啊
#include <stdio.h>#include <string.h>char she[6][6];int x, y;int ope(int com);void psh(int k, int kase);void swash(int i1, int j1, int i2, int j2);int main(){ int kase; for(kase = 1;; kase++) { int i, j, k = 1; int c; memset(she, '\0', sizeof(she)); for(i = 0; i < 5; i++) for(j = 0; j < 6; j++) { she[i][j] = getchar(); if(she[0][0] == 'Z' && she[0][1] == '\n') return 0; if(she[i][j] == ' ') {x = i; y = j;} } while((c = getchar()) != EOF && c != '0') { if(c != '\n' && ope(c)) {k = 0;break;} } if(kase > 1) printf("\n"); if(!k) for(;;) if((c = getchar()) == '0') break; psh(k, kase); getchar(); } return 0;}int ope(int com){ switch(com) { case 'A': x--;if(x < 0) return 1;swash(x, y, x + 1, y);break; case 'L': y--;if(y < 0) return 1;swash(x, y, x, y + 1);break; case 'R': y++;if(y > 4) return 1;swash(x, y, x, y - 1);break; case 'B': x++;if(x > 4) return 1;swash(x, y, x - 1, y);break; default :return 1; } return 0;}void swash(int i1, int j1, int i2, int j2){ int temp = she[i1][j1]; she[i1][j1] = she[i2][j2]; she[i2][j2] = temp;}void psh(int k, int kase){ int i, j; if(k) { printf("Puzzle #%d:\n", kase); for(i = 0; i < 5; i++) for(j = 0; j < 5; j++) {printf("%c",she[i][j]);printf((j == 4)?"\n":" ");} } else {printf("Puzzle #%d:\n", kase);printf("This puzzle has no final configuration.\n");}}
阅读全文
0 0
- 3.5 Puzzle UVA227
- 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
- mt2503 [Language]孟加拉字库文件说明
- 构造函数中调用构造函数new和delete使用小结
- 视频和音频
- 揭开知识库问答KB-QA的面纱3·信息抽取篇
- [转载]编译存储过程时遇到的library cache pin等待事件解决过程
- 3.5 Puzzle UVA227
- 云星数据---Scala实战系列(精品版)】:Scala入门教程053-Scala实战源码-Scala implicit 操作04
- 图片的二次采样
- sorry
- MFC多线程CWinThread实例
- Android中的动画
- Java之美[从菜鸟到高手演变]系列之博文阅读导航
- datagrid 选中行详情展示(显示格式化后字段)
- 自定义控件那些事儿 ----- 三【量测】