肥胖问题
BMI 三档判定,超重额外输出 BMI
正文
// 原题:https://oj.yecheng.tv/p/1361
// 题意:输入体重 m、身高 h,按 BMI 判体型。超重时先输出 BMI(cout 默认精度)再输出 Overweight。
// 思路:bmi=m/(h*h);<18.5 Underweight,[18.5,24) Normal,>=24 输出 bmi 与 Overweight。
// 复杂度:O(1)。
// 易错点:区间边界用大于等于;超重要先打印 BMI 再换行打印 Overweight。
#include <iostream>
using namespace std;
int main() {
double m, h;
cin >> m >> h;
double bmi = m / (h * h);
if (bmi < 18.5) cout << "Underweight" << endl;
else if (bmi < 24) cout << "Normal" << endl;
else { cout << bmi << endl << "Overweight" << endl; }
return 0;
}