알고리즘 풀이/백준
[3009] 백준 : 네 번째 점(C++)
데롱디롱
2020. 4. 26. 15:09
728x90

* 접근한 방법
- x, y 중 한 번씩만 입력된 숫자의 조합이 네 번째 점의 좌표가 됨
#include <iostream>
#include <map>
using namespace std;
int main()
{
map<int, int>x;
map<int, int>y;
int a, b;
for (int i = 0; i < 3; i++)
{
cin >> a >> b;
if (x.count(a) == 0)
x.insert(make_pair(a, 1));
else
x[a]++;
if (y.count(b) == 0)
y.insert(make_pair(b, 1));
else
y[b]++;
}
for (auto &i : x)
{
if (i.second == 1)
cout << i.first << " ";
}
for (auto &i : y)
{
if (i.second == 1)
cout << i.first ;
}
return 0;
}
- 뭔가 쉽게 푸는 방법이 있을 것 같아서 계속 고민했지만.. 생각이 안 나서.. 그냥 이렇게...