Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <string>
- #include <cctype>
- #include <stack>
- #include <queue>
- #include <list>
- #include <vector>
- #include <map>
- #include <set>
- #include <sstream>
- #include <stdlib.h>
- #include <cmath>
- #define LL unsigned long long
- using namespace std;
- char table[5][5];int px,py;
- int cont=0;
- bool move(char move){
- char temp;
- if(move=='L'){
- if(py-1>=0){
- temp=table[px][py-1];
- table[px][py]=temp;
- table[px][py-1]='x';
- py--;/*nueva posicion*/
- return true;
- }else return false;
- }else if(move=='R'){
- if(py+1<5){
- temp=table[px][py+1];
- table[px][py]=temp;
- table[px][py+1]='x';
- py++;/*nueva posicion*/
- return true;
- }else return false;
- }else if(move=='B'){
- if(px+1<5){
- temp=table[px+1][py];
- table[px][py]=temp;
- table[px+1][py]='x';
- px++;
- return true;
- }else return false;
- }else if(move=='A'){
- if(px-1>=0){
- temp=table[px-1][py];
- table[px][py]=temp;
- table[px-1][py]='x';
- px--;
- return true;
- }else return false;
- }else return false;/*caracter no reconocido*/
- }
- int main() {
- char cad[5];char moves[200];int n;bool termina;
- while(gets(cad)){
- if(strcmp(cad,"Z")==0) break;
- if(cont>0)printf("\n");
- cont++;
- termina=true;
- for (int j=0;j<5;j++){
- if(cad[j]==' ') table[0][j]='x';
- else table[0][j]=cad[j];
- if(cad[j]==' '){px=0;py=j;}
- }
- for(int i=1;i<=4;i++){
- gets(cad);
- for (int j=0;j<5;j++){
- if(cad[j]==' ') table[i][j]='x';
- else table[i][j]=cad[j];
- if(cad[j]==' '){px=i;py=j;}
- }
- }
- while(gets(moves)){
- n=strlen(moves);
- for (int i=0;i<n;i++){
- if(moves[i]!='0' && moves[i]!=' ') termina=move(moves[i]);
- else if(moves[i]!=0 && moves[i]==' ') continue;
- if(!termina) break;
- }
- if(moves[n-1]=='0') break;//indica que terminamos de leer el input
- }
- printf("Puzzle #%d:\n",cont);
- if(termina){
- for(int i=0;i<5;i++){
- for(int j=0;j<5;j++){
- if((j<4) &&(table[i][j]!='x')) printf("%c ",table[i][j]);
- else if(table[i][j]=='x'&& j<4) printf(" ");
- else if(table[i][j]=='x' && j==4)printf(" \n");
- else if(table[i][j]!='x' && j==4)printf("%c\n",table[i][j]);
- }
- }
- }else{
- printf("This puzzle has no final configuration.\n");
- }
- cad[0]='\0';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement