Enlace del título: https://vjudge.net/problem/UVA-227#author=0
Solución: esta pregunta no es difícil pero debe prestar atención a muchos puntos
1. Necesita ingresar un espacio, y cin no lee un espacio, por lo que necesita getchar, y cuando getchar está conectado a NULL, la prioridad es demasiado baja y necesita agregar ().
2. Cada vez que necesita envolver, necesita getchar ()
3. Informé un error de tiempo de ejecución al principio, la razón es que incluso si alcanza de 0 a 6, el cálculo se realizará más allá del límite, entonces el número de líneas se convertirá en -1 y se superará el límite. Si se agrega la solución, agregue un if
#include <iostream>
#include <cstdio>
#include <cstring>
usando el espacio de nombres std;
char qi [7] [7];
int main ()
{
int cou = 0;
memset (qi, 0, sizeof (qi));
while ((qi [1] [1] = getchar ())! = NULL) // cin ignora automáticamente los espacios, y getchar tiene una prioridad más baja, debe agregar ()
{
cou ++;
int flag = 1;
if (qi [1 ] [1] == 'Z') break;
for (int i = 2; i <= 5; i ++)
qi [1] [i] = getchar ();
getchar ();
for (int j = 2; j <= 5; j ++)
{
para (int i = 1; i <= 5; i ++)
qi [j] [i] = getchar ();
getchar ();
}
int bx, por;
for (int i = 1; i <= 5; i ++)
for (int j = 1; j <= 5; j ++)
if (qi [i] [j] == '')
{
bx = i;
por = j;
}
char ch, t;
para (;;)
{
ch = getchar ();
if (ch == '0') descanso;
if (flag == 1)
{
if (ch == 'A')
{
qi [bx] [by] = qi [bx-1] [by];
qi [bx-1] [por] = '';
bx--;
if (bx == 0) flag = 0;
}
else if (ch == 'B')
{
qi [bx] [by] = qi [bx + 1] [by];
qi [bx + 1] [por] = '';
bx ++;
if (bx == 6) flag = 0;
}
else if (ch == 'L')
{
qi [bx] [by] = qi [bx] [by-1];
qi [bx] [by-1] = '';
por--;
}
else if (ch == 'R')
{
qi [bx] [by] = qi [bx] [by + 1];
qi [bx] [por + 1] = '';
por ++;
if (por == 6) flag = 0;
}
}
}
getchar ();
if (cou> 1) cout << endl;
cout << "Puzzle #" << cou << ":" << endl;
if (flag == 0) cout << "Este rompecabezas no tiene una configuración final". << endl;
else
{
for (int i = 1; i <= 5; i ++)
{
for (int j = 1; j <= 5; j ++)
{
if (j! = 1) costo << '';
costo << qi [i] [j];
}
cout << endl;
}
}
memset (qi, 0, sizeof (qi));
}
devuelve 0;
}