※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 6825번 문제인 Body Mass Index이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/6825
6825번: Body Mass Index
The Body Mass Index (BMI) is one of the calculations used by doctors to assess an adult’s health. The doctor measures the patient’s height (in metres) and weight (in kilograms), then calculates the BMI using the formula BMI = weight/(height × height).
www.acmicpc.net
지문에 주어진, BMI를 구하는 공식을 이용해 문제를 해결하자.
입력으로 충분히 작고 정밀도가 낮은 실수가 들어온다고 가정하면 long double을 사용하는 것으로도 문제를 충분히 해결할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
typedef long double ld;
ld h, w;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> w >> h;
if (w > h * h * 25) cout << "Overweight";
else if (w < h * h * 18.5) cout << "Underweight";
else cout << "Normal weight";
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 24450 // C++] 国土分割 (Land Division) (0) | 2022.12.19 |
---|---|
[BOJ 26561 // C++] Population (0) | 2022.12.19 |
[BOJ 26531 // C++] Simple Sum (0) | 2022.12.19 |
[BOJ 2321 // Fortran] Crowing (0) | 2022.12.19 |
[BOJ 26545 // C++] Mathematics (0) | 2022.12.19 |