Algorithm/PS

[BOJ/백준] 6825 - Body Mass Index [C++/python]

chanwoong1 2023. 3. 2. 14:14
728x90

문제 링크

 

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 공식에 맞춰 조건에 따라 출력해주면 된다.

정답 코드

C++

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

#define fast ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define ll long long

int main() {
    fast;
    double w, h;
    cin >> w >> h;
    if (w / pow(h, 2) > 25) cout << "Overweight";
    else if (w / pow(h, 2) > 18.5) cout << "Normal weight";
    else cout << "Underweight";
}

python

w = float(input())
h = float(input())
if w / (h ** 2) > 25 : print("Overweight")
elif w / (h ** 2) > 18.5 : print("Normal weight")
else : print("Underweight")
728x90