코딩로그
[백준/BOJ/C++] 3009번 네 번째 점 본문
[문제]
세 점이 주어졌을 때, 축에 평행한 직사각형을 만들기 위해서 필요한 네 번째 점을 찾는 프로그램을 작성하시오.
[입력]
세 점의 좌표가 한 줄에 하나씩 주어진다. 좌표는 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;
}
[결과 화면]
'YJ > C++' 카테고리의 다른 글
[백준/BOJ/C++] 2753번 윤년 (0) | 2021.10.21 |
---|---|
[백준/BOJ/C++] 1085번 직사각형에서 탈출 (0) | 2021.10.21 |
[백준/BOJ/C++] 18247번 겨울왕국 티켓 예매 (0) | 2021.10.20 |
[백준/BOJ/C++] 4740번 거울, 오! 거울 (0) | 2021.10.20 |
[백준/BOJ/C++] 20540번 연길이의 이상형 (0) | 2021.10.20 |