[백준 3009] 네 번째 점

alsry._.112·2023년 8월 16일
0

백준

목록 보기
25/102

🔗문제 풀러가기
단계별로 풀어보기 단계 10의 3번째 문제이다.

문제 분석

세 점의 x, y좌표를 vector에 저장하여 비교해 나머지 한 점의 x, y좌표를 알아내었다.

코드

#include <iostream>
#include <vector>
 using namespace std;

 int main()
 {
	 vector<int> inputX, inputY;

	 int x = 0, y = 0;

	 for (int i = 0; i < 3; i++)
	 {
		 int inputx, inputy;

		 cin >> inputx >> inputy;

		 inputX.push_back(inputx);
		 inputY.push_back(inputy);
	 }

	 if (inputX[0] != inputX[1])
	 {
		 if (inputX[0] != inputX[2])
		 {
			 x = inputX[0];
		 }
		 else
		 {
			 x = inputX[1];
		 }
	 }
	 else
	 {
		 x = inputX[2];
	 }

	 if (inputY[0] != inputY[1])
	 {
		 if (inputY[0] != inputY[2])
		 {
			 y = inputY[0];
		 }
		 else
		 {
			 y = inputY[1];
		 }
	 }
	 else
	 {
		 y = inputY[2];
	 }

	 cout << x << " " << y;
 }

해석

  1. 입력받은 x, y를 저장할 int형 vector inputX, inputY와 찾아야할 x좌표, y좌표인 int형 x, y 를 선언한다.
  2. 반복문을 통해 x좌표와 y좌표를 3번 입력받아 vector에 넣어준다.
  3. 조건문을 통해 찾아내야할 x좌표와 y좌표를 찾아낸다.
  4. 이렇게 얻어낸 x좌표와 y좌표를 출력하면 끝!
profile
소통해요

0개의 댓글