[ create a new paste ] login | about

Link: http://codepad.org/fB5Fj5md    [ raw code | fork ]

C++, pasted on Oct 19:
#include <cmath>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <limits>

struct coord
{
	double x;
	double y;
	double z;
};

int main()
{
	std::string buff;
	std::vector<coord> v;
	double max = 0;
	double min = std::numeric_limits<double>::max();

	while(std::getline(std::cin, buff))
	{
		std::stringstream s(buff);

		coord c;
		s >> c.x >> c.y >> c.z;

		for(std::vector<coord>::iterator it = v.begin(); it != v.end(); ++it)
		{
			double d = std::sqrt((it->x - c.x) * (it->x - c.x) + (it->y - c.y) * (it->y - c.y) + (it->z - c.z) * (it->z - c.z));

			max = std::max(max, d);
			min = std::min(min, d);
		}

		v.push_back(c);
	}

	if(max < min)
	{
		std::cerr << "more than one datum." << std::endl;
	}
	else
	{
		std::cout << "max = " << max << std::endl;
		std::cout << "min = " << min << std::endl;
	}
}


Create a new paste based on this one


Comments: