Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. ifstream in("in.txt");
  5. ofstream out("out.txt");
  6. struct point {
  7.     int x, y, z;
  8. };
  9. double rass(point a, point b) {
  10.     return sqrt(pow(b.x - a.x, 2) + pow(b.y - a.y, 2) + pow(b.z - a.z, 2));
  11. }
  12. int main() {
  13.     setlocale(LC_ALL, "russian");
  14.     point a[10];
  15.     double sumras=0, minras=UINT_MAX;
  16.     int nump;
  17.     for (int i = 0; i < 10; i++) {
  18.         in >> a[i].x >> a[i].y >> a[i].z;
  19.     }
  20.     for (int i = 0; i < 10; i++) {
  21.         for (int j = 0; j < 10; j++) {
  22.             sumras += rass(a[i],a[j]); 
  23.         }
  24.         if (sumras < minras) {
  25.                 minras = sumras;
  26.                 nump = i;
  27.         }
  28.         out <<i <<'='<< sumras << endl;
  29.         sumras = 0;
  30.     }
  31.     out <<"Точка "<<nump+1<<" имеет минимальную сумму расстояний ="<< minras;
  32.     system("pause");
  33. return 0;
  34.  
  35. in.close();
  36. out.close();
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement