题目:

acm.hust.edu.cn/vjudge/roblem/viewProblem.action?id=19191

这道题本身难度不大,但输入输出时需要特别小心,一不留神就会出问题。

对于输入,如果要读入一行时:

没有空白字符,则直接使用scanf和%s即可;

有空白字符,使用gets,但要小心溢出;fgets一直不能正常工作,有待研究(gets会将缓冲区多余的\n扔掉,fgets会保留在字符串中);

对于要读入单个字符时:

使用scanf和“ %c”进行舍弃空白字符(注意空格),并且最后需要getchar来吃掉最后的回车;

scanf和“%c”会读入空白字符,和getchar相同。

只忽略回车,不忽略空格时,可将getchar放在以c==‘\n'为循环条件的do while中。

我心中的理想代码如下:

 #include<stdio.h>
#include<string.h>
const int LEN=;
const int MAX=;
const int y[]={,,,-};
const int x[]={-,,,};
char map[LEN][LEN];
int tra[];
bool legal(int pos){
return <=pos&&pos<LEN;
}
void Pmap(){
for(int cow=;cow<LEN;cow++){
printf("%c",map[cow][]);
for(int col=;col<LEN;col++)
printf(" %c",map[cow][col]);
printf("\n");
}
}
int main(){
tra['A']=;
tra['B']=;
tra['R']=;
tra['L']=; bool first=true;
int Case=;
//freopen("in","r",stdin);
//freopen("out","w",stdout);
int bx,by;
while(gets(map[])){
if(map[][]=='Z')break;
for(int col=;col<LEN;col++)
gets(map[col]);
for(int i=;i<LEN;i++)
for(int j=;j<LEN;j++)
if(map[i][j]==' '){
bx=i;by=j;
}
bool ok=true;
char c;
while(scanf(" %c",&c),c!=''){
if(!ok)continue;
int nx=bx+x[tra[c]],ny=by+y[tra[c]];
if(!legal(nx)||!legal(ny)){
ok=false;
continue;
}
map[bx][by]=map[nx][ny];
map[nx][ny]=' ';
bx=nx;by=ny;
}
getchar();
if(first)
first=false;
else
printf("\n");
printf("Puzzle #%d:\n",++Case);
if(ok)
Pmap();
else
printf("This puzzle has no final configuration.\n");
}
return ;
}

UVA 227 Puzzle - 输入输出的更多相关文章

  1. uva 227 Puzzle (UVA - 227)

    感慨 这个题实在是一个大水题(虽然说是世界决赛真题),但是它给出的输入输出数据,标示着老子世界决赛真题虽然题目很水但是数据就能卡死你...一直pe pe直到今天上午AC...无比感慨...就是因为最后 ...

  2. uva 227 Puzzle

     Puzzle  A children's puzzle that was popular 30 years ago consisted of a 5x5 frame which contained ...

  3. UVA 227 Puzzle(基础字符串处理)

    题目链接: https://cn.vjudge.net/problem/UVA-227 /* 问题 输入一个5*5的方格,其中有一些字母填充,还有一个空白位置,输入一连串 的指令,如果指令合法,能够得 ...

  4. Puzzle UVA - 227 PE代码求大佬指点

    ​ A children's puzzle that was popular 30 years ago consisted of a 5×5 frame which contained 24 smal ...

  5. UVA 277 Puzzle

    题意:输入5x5的字符串,输入操作,要求输出完成操作后的字符串. 注意:①输入的操作执行可能会越界,如果越界则按题目要求输出不能完成的语句. ②除了最后一次的输出外,其他输出均要在后面空一行. ③操作 ...

  6. UVA 227 周期串

    题意: 给一个字符串,寻找最短的循环节 如abcabcabcabc以3为周期,也按6和12为周期. 分析: 因为循环节肯定是相等的,所以枚举串长度的所有约数的循环节再判断是否相等即可. 我的方法是枚举 ...

  7. Uva227.Puzzle

    题目连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. UVA_Digit Puzzle UVA 12107

    If you hide some digits in an integer equation, you create a digit puzzle. The figure below shows tw ...

  9. uva live 12846 A Daisy Puzzle Game

    假设下一个状态有必败.那么此时状态一定是必胜,否则此时状态一定是必败 状压DP #include<iostream> #include<map> #include<str ...

随机推荐

  1. C#如何设置下拉COMMBOX为不可输入,只有下拉条目

    设置下拉框的DropDownStyle属性为DropDownList

  2. 安装laravel

    # 安装laravel 安装composer #安装 curl -sS https://getcomposer.org/installer | php #添加到PATH sudo mv compose ...

  3. Windows下Mysql解压缩版配置安装与卸载

    安装: ①解压Mysql到合适的位置! ②以管理员身份运行命令提示符(cmd),cd C:\Documents and Settings\Administrator\桌面\mysql-5.6.24-w ...

  4. Python正则匹配字母大小写不敏感在读xml中的应用

    需要解决的问题:要匹配字符串,字符串中字母的大小写不确定,如何匹配? 问题出现之前是使用字符串比较的方式,比如要匹配'abc',则用语句: if s == 'abc':#s为需要匹配的字符串 prin ...

  5. 文件:一个任务 - 零基础入门学习Python029

    文件:一个任务 让编程改变世界 Change the world by program 一个任务 这节课,我们需要一起来完成一个任务:将文件(record.txt)中的数据进行分割并按照以下规律保存起 ...

  6. 使用Hexo搭建GitPage

    资料: hexo官方文档:https://hexo.io/zh-cn/docs/ jekyll官方文档:http://jekyll.com.cn/docs/home/ 简介: 使用hexo和jekyl ...

  7. LibSvm介绍---调用方法及参数介绍

        libsvm是著名的SVM开源组件,目前有JAVA.C/C++,.NET 等多个版本,本人使用的是2.82 libsvm命名空间下主要使用类: svm_model 为模型类,通过训练或加载训练 ...

  8. 管理Activity 用户在主界面按两次回退退出系统

    1:定义一个用于管理Activity的类. /* * 用于管理Activity */ public class SysApp extends Application{ private List< ...

  9. C++11 new feature

    C++11 在类中引入了Move Constructor and the Move Assignmnt Operaetor,所谓‘move’指的是在复制对象时,left object 不用再创建资源, ...

  10. LeetCode_Container With Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...