Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请教:如何减少重复的输出

Posted by 90303103 at 2004-01-02 01:36:00 on Problem 1046
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator