Code:
#include <stdio.h>
#include <stdlib.h>
int **doolhof;
void printMaze(int *column, int *row){
int i, j;
for (i = 0; i < *row; i++){
for (j = 0; j < *column; j++){
printf("%d ", doolhof[i][j]);
}
printf("\n");
}
printf("\n");
}
void allocateMemory(int *column, int *row){
int i;
doolhof = calloc( *column, sizeof(int*));
for(i = 0; i < *column; i++){
doolhof[i] = calloc(*column, sizeof(int));
if (doolhof[i] == NULL) {
printf("Not enough memory\n");
exit(-1);
}
}
}
void getMaze(int *maxStap, int *column, int *row){
int i, j;
char temp;
scanf("%d %d", row, column);
*maxStap = (*row) * (*column) + 1;
allocateMemory(column, row);
scanf("%c", &temp);
for (i = 0; i < *row; i++){
for (j = 0; j < *column; j++){
scanf("%c", &temp);
if(debug) printf("i = %d, j=%d, temp = %c\n", i, j, temp);
switch (temp) {
case '.':
if(j == (*column) - 1 || j == 0 || i == (*row) - 1 || i == 0) doolhof[i][j] = -4;
else doolhof[i][j] = *maxStap;
break;
case '#':
doolhof[i][j] = -1;
break;
case '^':
doolhof[i][j] = -2;
break;
case '%':
doolhof[i][j] = -3;
break;
default:
j--;
break;
printMaze(column, row);
}
}
}
/* Midden van het doolhof op nul zetten */
doolhof[*row/2][*column/2] = 0;
}
void readIn(int *types, int *column, int *row, int *maxStep){
int gate, flower, personen, i, lengte;
scanf("%d %d", &gate, &flower);
scanf("%d", &personen);
for(i = 0; i < personen; i++){
scanf("%d", &lengte);
if(lengte > flower) {
if(lengte < gate) {
types[0] = 1;
} else {
types[2] = 1;
}
} else {
if( lengte < gate) {
types[1] = 1;
} else {
types[3] = 1;
}
}
}
getMaze(maxStep, column, row);
}
int main(int argc, char *argv[]){
int n, i, result;
int column = 0, row = 0, maxStep = 0;
int types[4];
q = malloc(sizeof(struct queue));
q->first = NULL;
q->last = NULL;
scanf("%d", &n);
resetTypes(types);
for (i = 0 ; i < n; i++){
readIn(types, &column, &row, &maxStep);
}
return 0;
}