하루하나코딩
백준 1085 : 직사각형에서 탈출
HAHAKO
2023. 3. 28. 10:53
코드
#include <iostream>
using namespace std;
int main(){
int x, y, w, h;
cin >> x >> y >> w >> h;
int temp1, temp2, ans;
if(x < y) temp1 = x;
else temp1 = y;
if(w-x < h-y) temp2 = w-x;
else temp2 = h-y;
if(temp1 < temp2) ans = temp1;
else ans = temp2;
cout << ans;
return 0;
}
알게된 점

그림을 보면 이해가 쉽다.
x, y, h-y, w-x중에 최소값을 구하면 된다.