#include #include typedef struct position { int x; int y; }Position; int main() { int N, i = 0, j, found = 0, k, numOfSteps = 0, tisicaKonstanta = 0, kos, p; Position position; position.x = 0; position.y = 0; Position *pole; int *readNumber; while ( scanf("%d", &N) > 0 ) { pole = (Position*) malloc (sizeof(Position)*1000000000); found = numOfSteps = tisicaKonstanta = i = 0; pole[tisicaKonstanta].x = 0; pole[tisicaKonstanta].y = 0; tisicaKonstanta++; readNumber = (int*) malloc (sizeof(int)*N); for ( p = 0; p < N; p++ ) { scanf("%d", &readNumber[p]); } while ( i < N && found == 0) { numOfSteps += readNumber[i]; //nastavi x a y noveho bodu ... funguje .. for ( k = 0; k < readNumber[i]; k++ ) { switch ( i % 4 ) { case 0: position.y++; break; case 1: //pole = (Position) realloc (pole, sizeof(pole)+readNumber); position.x++;// readNumber; break; case 2: //pole = (Position) realloc (pole, sizeof(pole)+readNumber); position.y--;// readNumber; break; case 3: //pole = (Position) realloc (pole, sizeof(pole)+readNumber); position.x--;// readNumber; break; } for ( j = 0; j < numOfSteps; j++ ) { if ( pole[j].x == position.x && pole[j].y == position.y ) { found = 1; } } if ( found == 0 ) { pole[tisicaKonstanta].x = position.x; pole[tisicaKonstanta++].y = position.y; } } i++; } //toto by malo byt v poriadku .. i--; if ( found == 1 ) { printf("%d\n",i); } else { printf("OK\n"); } i++; //while ( scanf("%d", &kos) != 0 ); } return 0; }