acm UVA 227 Puzzle字符串处理
来源:互联网 发布:linux 发送icmp请求包 编辑:程序博客网 时间:2024/04/26 15:52
This puzzle has no final configuratio
比较特殊的就是输入的指令可能是有换行
如:AB
LL
RR0
加上空格就好了
#include<bits/stdc++.h>
using namespace std;
char a[7][7];
int sx,sy;
bool mov(char x)
{
if(x=='A')
{
if(sx>0){
a[sx][sy]=a[sx-1][sy];sx--;a[sx][sy]=' ';return true;
}
else return false;
}
if(x=='B')
{
if(sx<4){
a[sx][sy]=a[sx+1][sy];sx++;a[sx][sy]=' ';return true;
}
else return false;
}
if(x=='L')
{
if(sy>0){
a[sx][sy]=a[sx][sy-1];sy--;a[sx][sy]=' ';return true;
}
else return false;
}
if(x=='R')
{
if(sy<4){
a[sx][sy]=a[sx][sy+1];sy++;a[sx][sy]=' ';return true;
}
else return false;
}
return false;
}
int main()
{
int cnt=0;
gets(a[0]);
while(strcmp(a[0],"Z")!=0)
{
for(int i=1;i<5;i++)
gets(a[i]);
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
if(a[i][j]==' ')sx=i,sy=j;
if(cnt==0)printf("Puzzle #%d:\n",++cnt);
else printf("\nPuzzle #%d:\n",++cnt);
char ch;
int flag=0;
scanf(" %c",&ch);
while(ch!='0')
{
if(!mov(ch)){flag=1;}
scanf(" %c",&ch);
}
if(flag==0){
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++){
if(j==0)printf("%c",a[i][j]);
else printf(" %c",a[i][j]);
}
printf("\n");
}
}
else printf("This puzzle has no final configuration.\n");
getchar();
gets(a[0]);
}
return 0;
}
- acm UVA 227 Puzzle字符串处理
- UVa 227 - Puzzle【字符串】
- 【ACM】Solution of UVA 227-Puzzle
- UVa 227 Puzzle 【数组和字符串】【模拟】
- UVA 227 Puzzle 【ACM/ICPC World Final 1993】
- 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
- 编程练习7(最短路)
- 编程练习
- Zuul 2 : The Netflix Journey to Asynchronous, Non-Blocking Systems
- css浮动
- 求最大公约数的算法
- acm UVA 227 Puzzle字符串处理
- HTML JavaScript 基础 (下)
- java解析String字符串xml 多级节点NodeList
- CentOS7.2 在GUI下关闭X Server
- Linux系统概念与体系(待修改)
- 对于一些经典库函数的源代码认识以及分析1.
- HDU2602Bone Collector(01背包)
- mysql多表联查
- navbar的一些坑