CCF-回收站选址(201912-2)-C语言(100分)

CCF-回收站选址(201912-2)-C语言(100分)_第1张图片
CCF-回收站选址(201912-2)-C语言(100分)_第2张图片

#include 
#include 
#define MAX 1000
#define LEVEL 5

typedef struct Around{
     
    int up;
    int down;
    int left;
    int right;
}around;

typedef struct Coordinate{
     
    int x;
    int y;
    around judge;
    int flag;
}coor;

int main()
{
     
    int n,i,j;
    scanf("%d",&n);
    coor pois[MAX];
    for(i=0;i<n;i++){
     
        scanf("%d %d",&pois[i].x,&pois[i].y);
        pois[i].flag=0;
        around a={
     0,0,0,0};
        pois[i].judge=a;
    }
    for(i=0;i<n;i++){
     
        for(j=0;j<n;j++){
     
            if(pois[i].x==pois[j].x&&pois[i].y+1==pois[j].y)
                pois[i].judge.up=1;
            if(pois[i].x==pois[j].x&&pois[i].y-1==pois[j].y)
                pois[i].judge.down=1;
            if(pois[i].x-1==pois[j].x&&pois[i].y==pois[j].y)
                pois[i].judge.left=1;
            if(pois[i].x+1==pois[j].x&&pois[i].y==pois[j].y)
                pois[i].judge.right=1;
        }
    }
    for(i=0;i<n;i++){
     
        if(pois[i].judge.up==1&&pois[i].judge.left==1&&pois[i].judge.down==1&&pois[i].judge.right==1){
     
            pois[i].flag=1;//可选为回收站
        }
    }
    int grade[LEVEL],score;
    memset(grade,0,LEVEL*sizeof(int));
    for(i=0;i<n;i++){
     
        if(pois[i].flag==1){
     
            score=0;
            for(j=0;j<n;j++){
     
                if(pois[i].x-1==pois[j].x&&pois[i].y+1==pois[j].y)
                    score++;
                if(pois[i].x-1==pois[j].x&&pois[i].y-1==pois[j].y)
                    score++;
                if(pois[i].x+1==pois[j].x&&pois[i].y+1==pois[j].y)
                    score++;
                if(pois[i].x+1==pois[j].x&&pois[i].y-1==pois[j].y)
                    score++;
            }
            grade[score]++;
        }
    }
    for(i=0;i<LEVEL-1;i++){
     
        printf("%d\n",grade[i]);
    }
    printf("%d",grade[i]);
    return 0;
}

你可能感兴趣的:(#,CSP,c语言,编程语言)