Spicke

yyyyy

Dec 19th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <iostream>
  5. #include <math.h>
  6. #include <ctime>
  7. using namespace std;
  8. struct point
  9. {
  10.     int x;
  11.     int y;
  12.  
  13. };
  14.  
  15. double Long(point &A, point &B);
  16.  
  17. int main(void)
  18. {
  19.     point *mas;
  20.     int n,x,y;
  21.     int line;
  22.     int k = 0;
  23.     int PointA = 0;
  24.     int PointB=1;
  25.     int a = 1;
  26.     cout << "Vvidite ckolko budet koordinat = ";
  27.     cin >> n;
  28.     srand(time(NULL));
  29.     if (n < 1)
  30.     {
  31.         n = 10;
  32.         mas = new point[n];
  33.         for (int i = 0; i < n; i++)
  34.         {
  35.             mas[i].x = rand() % 201 - 100;
  36.             mas[i].y = rand() % 201 - 100;
  37.         }
  38.     }
  39.     else
  40.     {
  41.         mas = new point[n];
  42.         for (int i = 0; i < n; i++)
  43.         {
  44.             cout << "mas[" << i << "] = ";
  45.             cin >> mas[i].x >> mas[i].y;
  46.         }
  47.     }
  48.     for (int i = 0; i<n; i++)
  49.     {
  50.         cout << mas[i].x << " " << mas[i].y <<  "\n";
  51.     }
  52.     line = Long(mas[1], mas[2]);
  53.  
  54.     for (int i = 0; i<n; i++)
  55.     {
  56.         for (int j = a; j<n; j++)
  57.         {
  58.             k++;
  59.             if (line < Long(mas[i], mas[j]))
  60.             {
  61.                 line = Long(mas[i], mas[j]);
  62.                 PointA = i;
  63.                 PointB = j;
  64.             }
  65.         }
  66.         a++;
  67.     }
  68.     x = (mas[PointA].x+ mas[PointB].x)/2;
  69.     y = (mas[PointA].y + mas[PointB].y) / 2;
  70.     cout << "\nKoordinatji tochki: (" << x << ";"<<y<<")"<< endl;
  71.     cout << "\nKolichestvo sravnenij: " << k << endl;
  72.     _getch();
  73.     return 0;
  74. }
  75. double Long(point &A, point &B)
  76. {
  77.     return sqrt(pow(B.x - A.x, 2) + pow(B.y - A.y, 2));
  78. }
Advertisement
Add Comment
Please, Sign In to add comment