ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

Why I get Crash (ACCESS_VIOLATION)? Help, please!
Posted by Kostya Tikhonov 7 Dec 2001 22:37
Look at my source:

#include <stdio.h>

#define M 200

int scr[M][M] = {0};
int scrb[M][M] = {0};
int N;

struct el_t {
    int x, y;
    el_t * n;
};

el_t * beg = 0;

void add(int x, int y)
{
    scrb[x][y] = 1;
    if (!beg){
        beg = new el_t;
        beg->x = x;
        beg->y = y;
        beg->n = 0;
        return;
    }
    el_t * t = beg;
    while (t->n) t = t->n;
    t->n = new el_t;
    t->n->x = x;
    t->n->y = y;
    t->n->n = 0;
}

int main ()
{
    scanf ("%d", &N);
    int fx, fy;
    for (int i =0; i < N; i++){
        int x, y;
        scanf ("%d %d", &x, &y);
        scr [x][y] = 1;
        if(!i){
            add (x, y);
            fx = x;
            fy =y;
        }
    }
    printf ("%d %d\n", fx, fy);

    while (beg){
        int tx = beg->x, ty = beg->y;

        int x = tx + 1, y = ty;
        if (scr[x][y] && !scrb[x][y]){
            add (x, y);
            printf ("R");
        }

        x = tx, y = ty + 1;
        if (scr[x][y] && !scrb[x][y]){
            add (x, y);
            printf ("T");
        }

        x = tx - 1, y = ty;
        if (scr[x][y] && !scrb[x][y]){
            add (x, y);
            printf ("L");
        }

        x = tx , y = ty - 1;
        if (scr[x][y] && !scrb[x][y]){
            add (x, y);
            printf ("B");
        }

        if (beg->n) printf (",\n");
        else printf (".\n");
        beg = beg->n;
    }


    return 0;
}