YJ/C++
[백준/BOJ/C++] 3009번 네 번째 점
Team DAON
2021. 10. 21. 16:34
[문제]
세 점이 주어졌을 때, 축에 평행한 직사각형을 만들기 위해서 필요한 네 번째 점을 찾는 프로그램을 작성하시오.
[입력]
세 점의 좌표가 한 줄에 하나씩 주어진다. 좌표는 1보다 크거나 같고, 1000보다 작거나 같은 정수이다.
[출력]
직사각형의 네 번째 점의 좌표를 출력한다.
[Source Code]
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
int main() {
int x[3], y[3], resultx, resulty;
for(int i = 0; i < 3; i++){
int inputx, inputy;
cin >> inputx >> inputy;
x[i] = inputx;
y[i] = inputy;
}
sort(x, x+3);
sort(y, y+3);
if(x[0] == x[1])
resultx = x[2];
else
resultx = x[0];
if(y[0] == y[1])
resulty = y[2];
else
resulty = y[0];
cout << resultx << " " << resulty;
}
[결과 화면]