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 liyan199311 at 2017-11-06 20:11:02 on Problem 1046
#include<iostream>
using namespace std;

int a[16][3] = {};

long distance(int* a1, int* a2)
{
	long temp1 = *(a1) - *(a2);
	long temp2 = *(a1 + 1) - *(a2 + 1);
	long temp3 = *(a1 + 2) - *(a2 + 2);
	return temp1 * temp1 + temp2 * temp2 + temp3 * temp3;
}

int search_best(int* input)
{
	long min = distance(a[0], input);
	int index = 0;
	long temp;
	for (int i = 1; i < 15; i++)
	{
		temp = distance(a[i], input);
		if (temp < min)
		{
			min = temp;
			index = i;
		}
	}
	return index;
}

void printt(int *input)
{
	cout << "(" << *input << "," << *(input + 1) << "," << *(input + 2) << ")";
}

void printt(int* input, int index)
{
	printt(input);
	cout << " maps to ";
	printt(a[index]);
	cout << endl;
}

void hand(int *input)
{
	int index = search_best(input);
	printt(input, index);
}

int main()
{
	int temp[3] = {};
	for (int i = 0; i < 16; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> a[i][j];
		}
	}
	while (1)
	{
		for (int i = 0; i < 3; i++)
		{
			cin >> temp[i];
		}
		if ((temp[0] == -1) && (temp[1] == -1) && (temp[2] == -1))
		{
			break;
		}
		else
		{
			hand(temp);
		}
	}
	return 0;
}

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