Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
请教:如何减少重复的输出#include<stdio.h> #include<math.h> void main(){ int a[100][3]={{0},{0}},i,j=0,k,b[100][3]={{0},{0}}; float min; for(i=0;;i++){ scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]); if(a[i][0]==-1&&a[i][1]==-1&&a[i][2]==-1){ j=i; break; } } for(i=0;i<=j;i++){ min=255*255*3; for(k=0;k<j;k++){ if((k!=i)&&((float)(sqrt((a[i][0]-a[k][0])*(a[i][0]-a[k][0])+(a[i][1]-a[k][1])*(a[i][1]-a[k][1])+(a[i][2]-a[k][2])*(a[i][2]-a[k][2]))))<min){ min=(float)(sqrt((a[i][0]-a[k][0])*(a[i][0]-a[k][0])+(a[i][1]-a[k][1])*(a[i][1]-a[k][1])+(a[i][2]-a[k][2])*(a[i][2]-a[k][2]))); b[i][0]=a[k][0]; b[i][1]=a[k][1]; b[i][2]=a[k][2]; } } } for(i=0;i<j;i++){ printf("(%d,%d,%d)maps to(%d,%d,%d)\n",a[i][0],a[i][1],a[i][2],b[i][0],b[i][1],b[i][2]); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator