개발자 톡
c++ 코드 공유
- 등록일
- 2025-02-07 00:02:40
- 조회수
- 39
- 작성자
- ghjkl0308
#include<iostream>
#include<map>
using namespace std;
struct Land{
map<int, int> height;
};
int main(int argc, char** argv)
{
int answer = 0;
int h = 0;
struct Land land[2][3];
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
cin >> h;
land[0][i].height[h]++;
land[1][j].height[h]++;
}
}
for(int i = 0; i < 2; i++){
for(int j = 0; j < 3; j++){
if(land[i][j].height.size() == 1){
answer = 0;
break;
}
else if(land[i][j].height.size() == 2){
auto it = land[i][j].height.begin();
int cost = (++it)->first - (--it)->first;
if(answer > cost || answer == 0) answer = cost;
}
else if(land[i][j].height.size() == 3)
if(answer == 0) answer = 2;
}
if(answer == 0) break;
}
cout << answer << endl;
return 0;
}
다양한 풀이들이 있어서 더 재밌네요