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
Cerinta
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 \le n \le 10$
- $-10 \le x_i, y_i \le 10$
Cod sursa
#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
