Advertisement
Pafnytiu

№5-1-15

May 10th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. struct Point
  6. {
  7. double x;
  8. double y;
  9. double z;
  10. };
  11.  
  12. double dlina(Point *p1, Point *p2)
  13. {
  14. double x = p2->x - p1->x;
  15. double y = p2->y - p1->y;
  16. double z = p2->z - p1->z;
  17.  
  18. return sqrt(x*x + y*y + z*z);
  19. }
  20.  
  21. int main()
  22. {
  23. setlocale(0, "");
  24. int n;
  25. cout << "Количество точек - ";
  26. cin >> n;
  27. Point *p = new Point[n];
  28. double *s = new double[n];
  29. cout << "Координаты точек\n";
  30. for (int i = 0; i < n; i++)
  31. {
  32. cout << "X "<< i << " - ";
  33. cin >> p[i].x;
  34. cout << "Y " << i << " - ";
  35. cin >> p[i].y;
  36. cout << "Z " << i << " - ";
  37. cin >> p[i].z;
  38. }
  39. for (int i = 0; i<n; i++)
  40. {
  41. double sum = 0;
  42. for (int j = 0; j<n; j++)
  43. {
  44. if (i != j)
  45. {
  46. sum += dlina(p + i, p + j);
  47. }
  48. }
  49. s[i] = sum;
  50. }
  51. int min = 0;
  52. for (int i = 0; i<n; i++)
  53. if (s[min] > s[i]) min = i;
  54. cout << "\nЭто точка (" << p[min].x << ", " << p[min].y << ", " << p[min].z << ")" << endl;
  55. delete[] s;
  56. delete[] p;
  57. system("pause");
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement