Challenge: Find the Point
Subdomeniu: Fundamentals (fundamentals)
Scor cont: 5.0 / 5
Submission status: Accepted
Submission score: 1.0
Submission ID: 464718610
Limbaj: cpp14
Link challenge: https://www.hackerrank.com/challenges/find-point/problem
Cerinta
Consider two points, $p = (p_x, p_y)$ and $q = (q_x, q_y)$. We consider the inversion or [point reflection](https://en.wikipedia.org/wiki/Point_reflection), $r = (r_x, r_y)$, of point $p$ across point $q$ to be a $180°$ rotation of point $p$ around $q$.
Given $n$ sets of points $p$ and $q$, find $r$ for each pair of points and print two space-separated integers denoting the respective values of $r_x$ and $r_y$ on a new line.
**Function Description**
Complete the *findPoint* function in the editor below.
*findPoint* has the following parameters:
- *int px, py, qx, qy:* x and y coordinates for points $p$ and $q$
**Returns**
- *int[2]:* x and y coordinates of the reflected point $r$
Input Format
The first line contains an integer, $n$, denoting the number of sets of points.
Each of the $n$ subsequent lines contains four space-separated integers that describe the respective values of $p_x$, $p_y$, $q_x$, and $q_y$ defining points $p = (p_x, p_y)$ and $q = (q_x, q_y)$.
Constraints
- $1 \le n \le 15$
- $-100 \le p_x, p_y, q_x, q_y \le 100$
Cod sursa
#include <iostream>
using namespace std;
int main() {
int n, px, py, mx, my;
cin >> n;
for (int i = 1; i <= n; i++){
cin >> px >> py >> mx >> my;
int rx = 2 * mx - px;
int ry = 2 * my - py;
cout << rx << " " << ry << endl;
}
return 0;
}
HackerRank Fundamentals – Find the Point
