题目:

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. hdu 2438

    Problem Description Mr. West bought a new car! So he is travelling around the city. One day he comes ...

  2. 【JAVA编码专题】总结

    第一部分:编码基础 为什么需要编码:用计算机看得懂的语言(二进制数)表示各种各样的字符. 一.基本概念 ASCII.Unicode.big5.GBK等为字符集,它们只定义了这个字符集内有哪些字符,以及 ...

  3. 使用ARM和VMSS创建自动扩展的web集群

    在很多的商业场景中,用户的访问,峰值时间都是很难预测的,尤其是做一些市场推广活动和促销的时候,到底部署什么规模的web集群合适,这一直是个问题,部署过量会造成高成本和资源不必要的浪费,部署过少,如果到 ...

  4. meta 属性

    几乎所有的网页里,我们可以看到类似下面这段的html代码:<head><meta http-equiv="content-Type" content=" ...

  5. HDU 4035 Maze(树形概率DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4035 题意:一棵树,从结点1出发,在每个结点 i 都有3种可能:(1)回到结点1 , 概率 Ki:(2 ...

  6. grok 添加字段

    filter { grok { match =>[ "message","%{IPORHOST:clientip} \[%{HTTPDATE:time}\] \&q ...

  7. c#提出中文首字母

           ; i < len; i++)             {                 myStr += getSpell(strText.Substring(i, ));   ...

  8. SNMP配置和常用命令OID(转)

    博文转至:http://blog.csdn.net/susu09new/article/details/12835191 OID值表示的意义(中文) .1.3.6.1.2.1.1操作系统相关的信息,其 ...

  9. CentOS6.4安装mplayer

    1.准备软件 mplayer官网:http://www.mplayerhq.hu/design7/news.html RPM Fusion网址:http://rpmfusion.org/ EPEL网址 ...

  10. Linux系统启动流程及grub重建(1)

    日志系统 Linux系统启动流程 PC: OS(Linux) POST-->BIOS(Boot Sequence)-->MBR(bootloader,446)-->Kernel--& ...