---
# System prepended metadata

title: UVA 10242 Fourth Point !!

---

# UVA 10242 Fourth Point !!
##  題目連結 [UVA 10242](https://vjudge.net/problem/UVA-10242)
### 題目內容
Given are the (x, y) coordinates of the endpoints of two adjacent sides of a parallelogram. Find the (x, y) coordinates of the fourth point.
### 輸入限制
Each line of input contains eight floating point numbers: the (x, y) coordinates of one of the endpoints of the first side followed by the (x, y) coordinates of the other endpoint of the first side, followed by the (x, y) coordinates of one of the endpoints of the second side followed by the (x, y) coordinates of the other endpoint of the second side. All coordinates are in meters, to the nearest mm. All coordinates are between −10000 and +10000. Input is terminated by end of file.
### 輸出限制
For each line of input, print the (x, y) coordinates of the fourth point of the parallelogram in meters, to the nearest mm, separated by a single space.
### 解題思路
1.題目會給定2條相鄰的邊，會發生4種不同的情況
2.(1) x1=x2 && y1=y2 (2) x1=x3 && y1=y3 (3) x0=x2 && y0=y2 (4) x0=x3 && y0=y3
3.xa，ya為第四點
### 程式碼
```cpp=
#include<bits/stdc++.h>
using namespace std;
int main(){
    double x[4],y[4];
    while(cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2]>>x[3]>>y[3]){
        double xa=0,ya=0;
        if(x[1]==x[2] && y[1]==y[2]){
            xa=x[0]+(x[3]-x[1]);
            ya=y[0]+(y[3]-y[1]);
        }
        else if(x[0]==x[2] && y[0]==y[2]){
            xa=x[1]+(x[3]-x[0]);
            ya=y[1]+(y[3]-y[0]);
        }
        else if(x[0]==x[3] && y[0]==y[3]){
            xa=x[1]+(x[2]-x[0]);
            ya=y[1]+(y[2]-y[0]);
        }
        else if(x[1]==x[3] && y[1]==y[3]){
            xa=x[0]+(x[2]-x[1]);
            ya=y[0]+(y[2]-y[1]);
        }
        printf("%.3f %.3f\n",xa,ya);
    }
}
```
## 測資
### Sample input
0.000 0.000 0.000 1.000 0.000 1.000 1.000 1.000
1.000 0.000 3.500 3.500 3.500 3.500 0.000 1.000
1.866 0.000 3.127 3.543 3.127 3.543 1.412 3.145
### Sample output
1.000 0.000
-2.500 -2.500
0.151 -0.398
##  中文題目連結 [zerojudge e512](https://zerojudge.tw/ShowProblem?problemid=e512)