일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 확률
- margin
- spring
- 강화학습
- Design Pattern
- Prefix Sums
- skt membership
- Gap
- 수학
- c++
- stl
- align-items
- Photoshop
- 소수
- series
- Codility
- CSS
- SK바이오사이언스
- 알고리즘
- 통신사할인
- 백준
- 에라토스테네스의 체
- pandas
- Javascript
- 포토샵
- Flexbox
- dataframe
- c
- grid
- 상태
Archives
- Today
- Total
sliver__
백준 - 네 번째 점(3009) 본문
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