UVa 227 Puzzle
2014-12-19 18:08
330 查看
这题和实验里的8 number很像,不过是字符而不是数字
%c吃回车。。。。然后加了一个getchar();
回忆了一下当时的思路
每次输入一个字母之后检查是否越界,如果没有就交换,然后更新空格的位置
不过这个是移动一但越界就输出 "哈,这个没有最终结果”
这个逻辑是不是很眼熟
没错,果断上break
然后就是无尽的调试
最后意识到break之后的字母也会作为下一组的输入
知道真相的我眼泪掉下来
改了一下,样例过了继续WA
仔细看题仔细看题
恩,我继续吐槽一下UVa的PE判定
%c吃回车。。。。然后加了一个getchar();
回忆了一下当时的思路
每次输入一个字母之后检查是否越界,如果没有就交换,然后更新空格的位置
不过这个是移动一但越界就输出 "哈,这个没有最终结果”
这个逻辑是不是很眼熟
没错,果断上break
然后就是无尽的调试
最后意识到break之后的字母也会作为下一组的输入
知道真相的我眼泪掉下来
改了一下,样例过了继续WA
仔细看题仔细看题
恩,我继续吐槽一下UVa的PE判定
#include<stdio.h> #include<algorithm> using namespace std; char a[6][6]; int main(){ int t=0; bool flag=true; while(++t && ~scanf("%c",&a[0][0]) && a[0][0]!='Z'){ int h,l,hdo,ldo; for(int i=0;i<5;i++){ for(int j=0;j<6;j++){ if(i||j) scanf("%c",&a[i][j]); if(a[i][j]==' ') h=i,l=j; } } char dong; hdo=h; ldo=l; bool p=true; while(~scanf("%c",&dong) && dong!='0'){ if(dong=='\n') continue; switch(dong){ case 'A': hdo--; break; case 'B': hdo++; break; case 'L': ldo--; break; case 'R': ldo++; break; } if(5<=ldo || ldo<0 || 5<=hdo || hdo<0){ hdo=h; ldo=l; p=false; } swap(a[h][l],a[hdo][ldo]); h=hdo,l=ldo; } if(t!=1) printf("\n"); printf("Puzzle #%d:\n",t); if(p){ for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ printf("%c",a[i][j]); if(j<4) printf(" "); } printf("\n"); } } else printf("This puzzle has no final configuration.\n"); getchar(); } return 0; }
相关文章推荐
- UVA_227 - Puzzle
- UVa 227_Puzzle
- UVA 227 Puzzle(基础字符串处理)
- UVA - 227 Puzzle
- UVA227 puzzle
- Uva - 227 - Puzzle
- UVa 227 Puzzle
- Uva-227 - Puzzle-AC
- 算法竞赛入门经典(第2版)习题3-5 谜题 Puzzle UVa227
- UVa227 Puzzle
- UVA227 puzzle 第一个超过一百行的代码。。。
- UVA 227 Puzzle
- 3.5 Puzzle UVA227
- UVa 227 - Puzzle
- UVa 227 Puzzle 【数组和字符串】【模拟】
- UVa 227 - Puzzle
- Puzzle, ACM/ICPC World Finals 1993, UVa227
- UVa 227 Puzzle
- Puzzle, ACM/ICPC World Finals 1993, UVa227
- Uva - 227 - Puzzle