topic description
in fact, there is no need to look at the title. Search UVa227 and you can see the title
.sources of topics and their own ideas
Puzzle, ACM/ICPC World Finals 1993, UVa227
related codes
/ / Please paste the code text below (do not replace the code with pictures)
-sharpinclude <stdio.h>
-sharpinclude <string.h>
-sharpdefine len 6
char matrix[len][len] = {
"TRGSJ", "XDOKI", "M VLN", "WPABE", "UQHCF"
};
int flag = 1, row = 2, col = 1;
void Above(char matrix[len][len], int row, int col) {
if (row > 0 && row <= 4) {
matrix[row][col] = matrix[--row][col];
matrix[row][col] = " ";
} else flag = 0;
}
void Below(char matrix[len][len], int row, int col) {
if (row >= 0 && row < 4) {
matrix[row][col] = matrix[PProw][col];
matrix[row][col] = " ";
} else flag = 0;
}
void Left(char matrix[len][len], int row, int col) {
if (col > 0 && col <= 4) {
matrix[row][col] = matrix[row][--col];
matrix[row][col] = " ";
} else flag = 0;
}
void Right(char matrix[len][len], int row, int col) {
if (col >= 0 && col < 4) {
matrix[row][col] = matrix[row][PPcol];
matrix[row][col] = " ";
} else flag = 0;
}
int main() {
char ins[100]; // instruction
gets(ins);
for (int i = 0; i < strlen(ins); PPi) {
if (ins[i] == "0") break;
if (ins[i] == "A") {Above(matrix, row, col);continue;}
else if (ins[i] == "B") {Below(matrix, row, col);continue;}
else if (ins[i] == "L") {Left(matrix, row, col);continue;}
else if (ins[i] == "R") {Right(matrix, row, col);continue;}
else flag = 0;
}
if (flag) {
for (int j = 0; j < len - 1; PPj) {
printf("\n");
for (int k = 0; k < len - 1; PPk)
printf("%c ", matrix[j][k]);
}
} else printf("This puzzle has no final configuration.");
return 0;
}
what result do you expect? What is the error message actually seen?
row and col restore 2, 1
when calling Above, Below, Left, and Right. How to keep row and col modified after calling?