Advertisement
bogdanNiculeasa

Problema Pbinfo structs

Jan 12th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include<cmath>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. struct  Point{
  8.     int x;
  9.     int y;
  10. };
  11.  
  12. int main() {
  13.  
  14.     struct Point points[100];
  15.     int n;
  16.     cin >> n;
  17.     for(int i =0; i < n; i++) {
  18.         cin>>points[i].x;
  19.         cin>>points[i].y;
  20.     }
  21.  
  22.     float distance = -1;
  23.     int numberOfPoints = 0;
  24.  
  25.     for(int i =0; i < n; i++) {
  26.         float currentDistance = sqrt((points[i].x -0)*(points[i].x -0)  +  (points[i].y -0)*(points[i].y -0));
  27.         if(currentDistance > distance) {
  28.             distance = currentDistance;
  29.             numberOfPoints = 1;
  30.         } else if(currentDistance == distance) {
  31.             numberOfPoints++;
  32.         }
  33.     }
  34.  
  35.     cout << distance << " " << numberOfPoints;
  36.     return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement