sliver__

백준 - 네 번째 점(3009) 본문

CS/알고리즘

백준 - 네 번째 점(3009)

sliver__ 2021. 11. 18. 19:49
728x90

https://www.acmicpc.net/problem/3009

 

3009번: 네 번째 점

세 점이 주어졌을 때, 축에 평행한 직사각형을 만들기 위해서 필요한 네 번째 점을 찾는 프로그램을 작성하시오.

www.acmicpc.net

네 번째 점

 

세 개의 점이 주어지고 나머지 한 점을 찾는 문제입니다.

(a,b) (a,c), (d,c), (d, b)가 존재한다고 했을 때

한 가지 점이 없으면 홀수인 개수의 점을 찾으면 됩니다.

 

제출한 코드는 아래와 같습니다

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

int main()
{
	int x, y, resX, resY;
	map<int, int> xMap, yMap;
	map<int, int>::iterator xIter, yIter;
	for (int i = 0; i < 3; i++)
	{
		cin >> x >> y;
		xIter = xMap.find(x);
		yIter = yMap.find(y);
		if (xIter == xMap.end())
		{
			xMap.insert({ x, 1 });
		}
		else
		{
			xMap[x]++;
		}
		if (yIter == yMap.end())
		{
			yMap.insert({ y, 1 });
		}
		else
		{
			yMap[y]++;
		}
	}

	for (xIter = xMap.begin(); xIter != xMap.end(); ++xIter)
	{
		if (xIter->second % 2 == 1) resX = xIter->first;
	}

	for (yIter = yMap.begin(); yIter != yMap.end(); ++yIter)
	{
		if (yIter->second % 2 == 1) resY = yIter->first;
	}
	cout << resX << " " << resY << endl;
}

 

728x90

'CS > 알고리즘' 카테고리의 다른 글

백준 - 팩토리얼(10872)  (0) 2021.11.18
백준 - 택시기하학(3053)  (0) 2021.11.18
백준 - 직각삼각형(4153)  (0) 2021.11.18
백준 - 직사각형에서 탈출(1085)  (0) 2021.11.18
백준 - 골드바흐의 추측(9020)  (0) 2021.11.18
Comments