Toliak

v1

Sep 28th, 2018
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. #define ABS(x) ((x) < 0 ? -(x) : (x))
  5.  
  6. typedef std::pair<double, double> Point;
  7.  
  8. double count(Point points[]) {
  9.     double sum = 0;
  10.     for (int i = 0; i < 3; i++) {
  11.         Point oppositeCenter;
  12.         oppositeCenter.first = (points[i].first + points[(i + 1) % 3].first) / 2;
  13.         oppositeCenter.second = (points[i].second + points[(i + 1) % 3].second) / 2;
  14.  
  15.         Point currentPoint = points[(i + 2) % 3];
  16.  
  17.         sum += sqrt(pow(currentPoint.first - oppositeCenter.first, 2.) +
  18.                     pow(currentPoint.second - oppositeCenter.second, 2.));
  19.     }
  20. }
  21.  
  22. int main() {
  23.     Point points[3];
  24.     for (int i = 0; i < 3; i++) {
  25.         std::cout << "Input X" << i << ", Y" << i << ":" << std::endl;
  26.         std::cin >> points[i].first >> points[i].second;
  27.     }
  28.     std::cout << "Sum of medians: " << count(points) << std::endl;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment