본문 바로가기

온라인 코딩/수학(Math)

[백준] 3009번 직사각형에서 탈출

문제

 

백준 직사각형에서 탈출

 

소스코드

#include<iostream>
#include<array>
#include<algorithm>
int main() {
	std::array<int,4>position;
	int x, y, w, h;
	std::cin >> x >> y >> w >> h;
	position[0] = x, position[1] = y;  //왼쪽 아래 꼭지점이 0,0이기 때문에 그대로 값을 넣는다.
	position[2] = w - x, position[3] = h - y; //오른쪽 꼭지점의 위치를 구한다.
	std::cout << *(std::min_element(position.cbegin(), position.cend())) << std::endl;
	system("pause");
}

 

 

후기

어려운 문제는 아니었지만 std::min 사용과 system("pause") 사용으로 인해 오류가 발생했던 문제였다.

std::min에서 최소값이 안 나와서 고생했지만 std::min_element와 차이점을 다시 상기할 수 있었다.

 

 

 

 

출처 및 레퍼런스

std::min_element https://en.cppreference.com/w/cpp/algorithm/min_element

문제 출처: https://www.acmicpc.net/problem/1085

'온라인 코딩 > 수학(Math)' 카테고리의 다른 글

[백준] 2581번 소수  (0) 2020.04.03
[백준] 1978번 소수 찾기  (0) 2020.02.08
[백준] 1712번 순익분기점  (0) 2020.02.07
[백준] 10539번 수빈이와 수열  (0) 2020.01.27
[백준] 4153번 직각삼각형  (1) 2019.12.16