Soluție HackerRank pentru Points On a Line, subdomeniul Geometry, în C++14. Include cerința formatată, exemple, explicația pașilor și cod sursă.

  • Problemă: Points On a Line
  • Domeniu: Geometry
  • Limbaj: C++14

Challenge: Points On a Line

Scor cont: 10.0 / 10

Submission status: Accepted

Submission score: 1.0

Submission ID: 464719801

Limbaj: cpp14

Link challenge: https://www.hackerrank.com/challenges/points-on-a-line/problem

Cerință

Given n two-dimensional points in space, determine whether they lie on some vertical or horizontal line. If yes, print *YES*; otherwise, print *NO*.

Input Format

The first line contains a single positive integer, n, denoting the number of points.
Each line i of n subsequent lines contain two space-separated integers detailing the respective values of x_i and y_i (i.e., the coordinates of the i-th point).

Output Format

Print *YES* if all points lie on some horizontal or vertical line; otherwise, print *NO*.

Constraints

- 2 ≤ n ≤ 10
- -10 ≤ x_i, y_i ≤ 10

Cod sursă

#include<set>
#include<iostream>

using namespace std;

int main(){
    int n; cin>>n;

    set<int> x_cordinate, y_cordinate;

    for(int i=0;i<n;i++){
        int x,y; cin>>x>>y;

        x_cordinate.insert(x);
        y_cordinate.insert(y);
    }
    if((x_cordinate.size()==1) || (y_cordinate.size()==1))
        cout<<"YES";
    else
        cout<<"NO";

    return 0;
}
HackerRank Geometry – Points On a Line