Uva 227 - Puzzle (数组和字符串)
2015-10-20 16:51
323 查看
题不难,就是小坑涉及到基础需注意。。。
比如:
字符串后面的'\0'和'0'不同。
getchar函数读数据直到用户按回车为止(回车字符也放在缓冲区中)。
还有题目pdf中样例二 不能直接复制到控制台调试,因为没空格,要手动测试这组。
View Code
比如:
字符串后面的'\0'和'0'不同。
getchar函数读数据直到用户按回车为止(回车字符也放在缓冲区中)。
还有题目pdf中样例二 不能直接复制到控制台调试,因为没空格,要手动测试这组。
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cstdlib> #include<cmath> #include<cctype> #include<vector> #include<queue> #include<map> #include<set> #define eps 10e-6 using namespace std; typedef long long ll; char mp[8][8]; char op[205],op1[105]; int main() { int ex,ey; int cas = 1; while(gets(mp[0])!=NULL) { if(mp[0][0]=='Z') break; if(cas!=1) printf("\n"); for(int i=1;i<5;i++) gets(mp[i]); for(int i=0;i<5;i++) { // printf("ok: %s\n",mp[i]); for(int j=0;j<5;j++) { if(mp[i][j]==' ') { ex = i; ey = j; } } } printf("Puzzle #%d:\n",cas++); memset(op,0,sizeof(op)); memset(op1,0,sizeof(op1)); int flag = 0; char c; gets(op); int l = strlen(op); while(op[l-1]!='0') { gets(op1); strcat(op,op1); l = strlen(op); } for(int i=0;i<l-1;i++) { // printf("c=%c ex=%d ey=%d\n",c,ex,ey); c = op[i]; if(c=='A') { if(ex == 0) { flag = 1; break; } mp[ex][ey] = mp[ex-1][ey]; mp[ex-1][ey] = ' '; ex--; } else if(c=='B') { if(ex == 4) { flag = 1; break; } mp[ex][ey] = mp[ex+1][ey]; mp[ex+1][ey] = ' '; ex++; } else if(c=='L') { if(ey == 0) { flag = 1; break; } mp[ex][ey] = mp[ex][ey-1]; mp[ex][ey-1] = ' '; ey--; } else { if(ey == 4) { flag = 1; break; } mp[ex][ey] = mp[ex][ey+1]; mp[ex][ey+1] = ' '; ey++; } } if(flag){ printf("This puzzle has no final configuration.\n"); } else { for(int i=0;i<5;i++) { for(int j=0;j<4;j++) { printf("%c ",mp[i][j]); } printf("%c\n",mp[i][4]); } //printf("\n"); } // getchar(); } return 0; }
View Code
相关文章推荐
- with as (转)
- Lucene4.7.2实例之用索引搜索文件
- KMP算法-字符串匹配
- 第八周项目三顺序串算法
- iOS调试技巧
- Android图像处理
- 《黑书》后缀数组学习笔记.
- 汽车诊断协议ISO15765
- 【转】Oracle存储过程常用技巧
- redirect forward区别
- 二、共享你的代码 ----- 函数模块
- Boosting
- 【MySQL】【leetcode】 Duplicate Emails解题报告
- Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
- 友盟分享中 分享QQ及新浪微博中的一些遇到分享失败及一些常见问题
- Android持续集成--JENKINS+GRADLE+JACOCO+SONARQUBE(三)
- mybatis There is no getter for property named 'xx' in 'class java.lang.String
- 作用域
- [daemon进程] 使用PHP脚本来写Daemon程序
- 结构体成员和结构体指针初始化