UVa OJ 152 排序?

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

typedef struct{
	int x;
	int y;
	int z;
}point;

point ps[5001];

void func(int len){
	float res[5001] = {0};
	int dis[5001] = {0};
	int fin[10] = {0};
	int i,j;
	for(i=0; i < len; i++){
		for(j=0; j <len;j++){		
			dis[j] = (ps[i].x - ps[j].x)*(ps[i].x - ps[j].x)+ (ps[i].y - ps[j].y)*(ps[i].y - ps[j].y)+ (ps[i].z - ps[j].z)*(ps[i].z - ps[j].z);			
		}
		
		int temp = 65535;
		for( j = 0; j < len; j++){
			if(dis[j] < temp && j != i){
				temp = dis[j];
				res[i] = sqrt(dis[j]);	
			}
		}		
		memset(dis, 0, sizeof dis);	
	}
	
	for(j=0; j<len;j++){		
		fin[(int)res[j]] += 1;	
	}	
	
	for(i=0; i<10; i++)
		printf("%4d", fin[i]);
	printf("\n");

}

int main(void){
	int tx, ty, tz;
	int len = 0;
/*	FILE* fp = fopen("data.txt", "r");*/
	while(fscanf(stdin, "%d%d%d", &tx, &ty, &tz) != EOF){
		if(tx == 0 && ty == 0 && tz == 0)
			break;
		ps[len].x = tx;
		ps[len].y = ty;
		ps[len].z = tz;		
		len += 1;			
	}
	func(len);
/*	system("pause");*/
	return 0;		
}
问题: 如何用排序?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值