★ solved.ac 난이도 : B3
(작성 시점 기준)
[문제 본문 링크]
★ 풀이
문제에 주어진 현재 위치(x, y)와 직사각형의 크기(w, h)에서 min(min(x, y), min(w-x, h-y))의 값을 출력하시면 됩니다.
min(x, y) 부분은 (0, 0)에서의 거리를 계산하기 위해 사용되고, min(w-x, h-y) 부분은 (w, h)에서의 거리를 계산하기 위해 사용됩니다.
[소스 코드]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int main(void){ | |
int x,y,w,h; | |
cin>>x>>y>>w>>h; | |
cout<<min(min(x,w-x),min(y,h-y)); | |
return 0; | |
} |
★ 틀린 점이 있다면 알려주세요~!