UVa 227 Puzzle
来源:互联网 发布:网络融资平台靠谱吗 编辑:程序博客网 时间:2024/05/18 01:41
不知道为什么总是编译错误,未定义gets()。
#include <algorithm> #include <iostream> #include <cstdlib> #include <stdio.h>#include <string.h>int main() { //freopen("227.txt", "r", stdin); char map[5][6], cmd; int cases = 0; while(gets(map[0])) { if(!strcmp(map[0], "Z")) break; if(cases) puts(""); printf("Puzzle #%d:\n", ++cases); gets(map[1]), gets(map[2]), gets(map[3]), gets(map[4]); int i, j, x, y; for(i = 0; i < 5; i++) { for(j = 0; j < 5; j++) { if(map[i][j] == ' ' || map[i][j] == '\0') x = i, y = j; } } int error = 0; while(1) { cmd = getchar(); if(cmd == 'A') { if(x == 0) { error = 1; break; } map[x][y] = map[x-1][y]; x--; } else if(cmd == 'B') { if(x == 4) { error = 1; break; } map[x][y] = map[x+1][y]; x++; } else if(cmd == 'L') { if(y == 0) { error = 1; break; } map[x][y] = map[x][y-1]; y--; } else if(cmd == 'R') { if(y == 4) { error = 1; break; } map[x][y] = map[x][y+1]; y++; } else if(cmd == '0') break; } if(cmd != '0') { while((cmd = getchar()) != '0'); } while((cmd = getchar()) != '\n'); if(error) puts("This puzzle has no final configuration."); else { map[x][y] = ' '; for(i = 0; i < 5; i++) { for(j = 0; j < 5; j++) { if(j) putchar(' '); putchar(map[i][j]); } puts(""); } } memset(map, 0, sizeof(map)); } 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
- JAVA三大特性深入理解--多态
- Kafka快速入门
- 彻底搞定C语言指针详解-完整版-时候初学者-必备
- 文件IO操作
- js入门:建立一个图片库
- UVa 227 Puzzle
- Dom对象与jQuery对象的区别
- 杭电OJ_(2047)阿牛的EOF牛肉串
- Lintcode-递归-177 把排序数组转换为高度最小的二叉搜索树
- 交错序列
- MFC学习笔记-串口通信
- poj 4115:鸣人和佐助
- Qt5 文件编码
- 系统地讲述Cookie与Session机制