[ create a new paste ] login | about

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

C++, pasted on Oct 19:
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <vector>
using namespace std;
struct coord {
  double x, y, z;
  coord(double x, double y, double z) { this->x = x; this->y = y; this->z = z; }
};
int main() {
  string buff;
  vector<coord> v;
  double max = -1.0, min = -1.0;
  while (getline(cin, buff)) {
    stringstream s;
    double x, y, z;
    s << buff;
    s >> x >> y >> z;
    for (vector<coord>::iterator p = v.begin(); p != v.end(); p++) {
      double d;
      d = sqrt((p->x - x) * (p->x - x) + (p->y - y) * (p->y - y) + (p->z - z) * (p->z - z));
      if (v.size() == 1)
        max = min = d;
      else {
        if (d > max)
          max = d;
        if (d < min)
          min = d;
      }
    }        
    v.push_back(coord(x, y, z));
  }
  if (min < 0.0 || max < 0.0)
    cerr << "more than one datum." << endl;
  else {
    cout << "max = " << max << endl;
    cout << "min = " << min << endl;
  }
  return 0;
}
/* end */


Output:
1
more than one datum.


Create a new paste based on this one


Comments: