2020.10.07
By ljm
C语言满分答案:
#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { struct distance{ int di; int num; }; int i,X,Y,a,b; scanf("%d %d %d",&i,&X,&Y); struct distance po[i],z; int x[i],y[i]; for(a=0;a<i;a++){ scanf("%d %d",&x[a],&y[a]); po[a].di=(X-x[a])*(X-x[a])+(Y-y[a])*(Y-y[a]); po[a].num=a+1; } for(a=0;a<3;a++){ for(b=i-1;b>a;b--){ if(po[b].di<po[b-1].di){ z=po[b]; po[b]=po[b-1]; po[b-1]=z; } } } for(a=0;a<3;a++){ printf("%d\n",po[a].num); } return 0; }