[ create a new paste ] login | about

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

C++, pasted on Oct 19:
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <vector>
const double MIN_INIT = 10000;
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 = 0.0, min = MIN_INIT;
  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 (d > max)
        max = d;
      if (d < min)
        min = d;
    }        
    v.push_back(coord(x, y, z));
  }
  cout << "max = " << max << endl;
  cout << "min = " << min << endl;
  return 0;
}
/* end */


Output:
1
2
max = 0
min = 10000


Create a new paste based on this one


Comments: