[c]

/*@BEGIN_OF_SOURCE_CODE*/

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

/* @JUDGE_ID: 22113ZY 101 C */

#define MAXSIZE 24

void initializeBlocks(int M[MAXSIZE][MAXSIZE], int num)

{

int i,j;

for (i = 0; i < num ; i++)

{

for (j = 0; j < num ; j++)

{

if (j == 0)

M

*[j] = i;*

else

M

else

M

*[j] = -1;*

}

}

return;

}

void display(int M[MAXSIZE][MAXSIZE], int num)

{

int i,j;

for (i = 0; i < num ; i++)

{

printf("%d: ", i);

for (j = 0; j < num ; j++)

{

if (M}

}

return;

}

void display(int M[MAXSIZE][MAXSIZE], int num)

{

int i,j;

for (i = 0; i < num ; i++)

{

printf("%d: ", i);

for (j = 0; j < num ; j++)

{

if (M

*[j] != -1)*

printf("%d ", Mprintf("%d ", M

*[j]);*

}

printf("\n");

}

return;

}

void clear(int M[MAXSIZE][MAXSIZE], int num, int block)

{

int i,j;

for (i = 0; i < num ; i++)

{

for (j = 0; j < num ; j++)

{

if (M}

printf("\n");

}

return;

}

void clear(int M[MAXSIZE][MAXSIZE], int num, int block)

{

int i,j;

for (i = 0; i < num ; i++)

{

for (j = 0; j < num ; j++)

{

if (M

*[j] == block)*

{

j++;

while(j < num && M{

j++;

while(j < num && M

*[j] != -1)*

{

M[(M{

M[(M

*[j])][0] = M**[j];*

MM

*[j] = -1;*

j++;

}

return;

}

}

}

}

void stack(int M[MAXSIZE][MAXSIZE], int num, int fromBlock, int toBlock)

{

int i,j;

int *fp, *tp;

for (i = 0; i < num ; i++)

{

for (j = 0; j < num ; j++)

{

if (Mj++;

}

return;

}

}

}

}

void stack(int M[MAXSIZE][MAXSIZE], int num, int fromBlock, int toBlock)

{

int i,j;

int *fp, *tp;

for (i = 0; i < num ; i++)

{

for (j = 0; j < num ; j++)

{

if (M

*[j] == fromBlock)*

fp = &M[i][j];

if (M[i][j] == toBlock)

tp = &M[i][j];

}

}

while (*tp != -1)

tp++;

while (*fp != -1)

{

*tp = *fp;

*fp = -1;

fp++;

tp++;

}

}

int main(void)

{

/* FILE *inp, *outp; */

int i, j, k;

int quit = 0;

int numBlocks = 0;

int ignore = 0;

int matrix[MAXSIZE][MAXSIZE];

char line[100];

int a,b;

char cmd[5];

char action[6];

/*

if ((inp = fopen("prob101input.txt","r")) == NULL)

{

printf("FILE READ ERROR");

exit(EXIT_FAILURE);

}

if ((outp = fopen("prob101output.txt","w")) == NULL)

{

printf("FILE WRITE ERROR");

exit(EXIT_FAILURE);

}

*/

fgets(line,100,stdin);

sscanf(line,"%d", &numBlocks);

if (numBlocks < 1 || numBlocks > 24)

return 0;

initializeBlocks(matrix, numBlocks);

display(matrix, numBlocks);

while (!feof(stdin))

{

fgets(line,100,stdin);

sscanf(line,"%s%d%s%d", cmd, &a, action, &b);

if (strcmp(cmd,"quit") == 0)

{

display(matrix, numBlocks);

return 0;

}

if (a == b)

continue;

for (i = 0; i < numBlocks ; i++)

{

for (j = 0; j < numBlocks ; j++)

{

if (matrix[i][j] == a)

{

k = 0;

while (k < numBlocks && matrix[i][k] != -1)

{

if (matrix[i][k] == b)

{

ignore = 1;

goto IgnoreThis;

}

k++;

}

}

}

}

IgnoreThis:

if (ignore)

{

ignore = 0;

continue;

}

if (strcmp(cmd,"move") == 0)

{

if (strcmp(action,"onto") == 0)

{

clear(matrix, numBlocks, a);

clear(matrix, numBlocks, b);

stack(matrix, numBlocks, a, b);

}

else

{

clear(matrix, numBlocks, a);

stack(matrix, numBlocks, a, b);

}

}

else if (strcmp(cmd,"pile") == 0)

{

if (strcmp(action,"onto") == 0)

{

clear(matrix, numBlocks, b);

stack(matrix, numBlocks, a, b);

}

else

stack(matrix, numBlocks, a, b);

}

display(matrix, numBlocks);

}

return 0;

}

/* @END_OF_SOURCE_CODE */

[/c]

Anyone have a clue as to what I am doing wrong here? Any help would be most appreciated. I mostly just want to rule out the possibility that I am submitting the code incorrectly or something of that nature.fp = &M[i][j];

if (M[i][j] == toBlock)

tp = &M[i][j];

}

}

while (*tp != -1)

tp++;

while (*fp != -1)

{

*tp = *fp;

*fp = -1;

fp++;

tp++;

}

}

int main(void)

{

/* FILE *inp, *outp; */

int i, j, k;

int quit = 0;

int numBlocks = 0;

int ignore = 0;

int matrix[MAXSIZE][MAXSIZE];

char line[100];

int a,b;

char cmd[5];

char action[6];

/*

if ((inp = fopen("prob101input.txt","r")) == NULL)

{

printf("FILE READ ERROR");

exit(EXIT_FAILURE);

}

if ((outp = fopen("prob101output.txt","w")) == NULL)

{

printf("FILE WRITE ERROR");

exit(EXIT_FAILURE);

}

*/

fgets(line,100,stdin);

sscanf(line,"%d", &numBlocks);

if (numBlocks < 1 || numBlocks > 24)

return 0;

initializeBlocks(matrix, numBlocks);

display(matrix, numBlocks);

while (!feof(stdin))

{

fgets(line,100,stdin);

sscanf(line,"%s%d%s%d", cmd, &a, action, &b);

if (strcmp(cmd,"quit") == 0)

{

display(matrix, numBlocks);

return 0;

}

if (a == b)

continue;

for (i = 0; i < numBlocks ; i++)

{

for (j = 0; j < numBlocks ; j++)

{

if (matrix[i][j] == a)

{

k = 0;

while (k < numBlocks && matrix[i][k] != -1)

{

if (matrix[i][k] == b)

{

ignore = 1;

goto IgnoreThis;

}

k++;

}

}

}

}

IgnoreThis:

if (ignore)

{

ignore = 0;

continue;

}

if (strcmp(cmd,"move") == 0)

{

if (strcmp(action,"onto") == 0)

{

clear(matrix, numBlocks, a);

clear(matrix, numBlocks, b);

stack(matrix, numBlocks, a, b);

}

else

{

clear(matrix, numBlocks, a);

stack(matrix, numBlocks, a, b);

}

}

else if (strcmp(cmd,"pile") == 0)

{

if (strcmp(action,"onto") == 0)

{

clear(matrix, numBlocks, b);

stack(matrix, numBlocks, a, b);

}

else

stack(matrix, numBlocks, a, b);

}

display(matrix, numBlocks);

}

return 0;

}

/* @END_OF_SOURCE_CODE */

[/c]

Anyone have a clue as to what I am doing wrong here? Any help would be most appreciated. I mostly just want to rule out the possibility that I am submitting the code incorrectly or something of that nature.