1 条题解
-
0
【例19.2】 判断身材
解题思路
先计算标准体重 (h-100)×0.9,再与其 1.1 倍和 0.9 倍比较。严格超过上限为 fat,严格低于下限为 thin,其余 standard。
正确性说明
两个严格条件与题面一致,边界相等自动落入标准范围。
易错点
输入身高为厘米,不换算成米。
复杂度
输入规模固定,时间 O(1),额外空间 O(1)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); double h, w; cin >> h >> w; double s = (h - 100) * 0.9; if (w > s * 1.1) cout << "fat\n"; else if (w < s * 0.9) cout << "thin\n"; else cout << "standard\n"; return 0; }
- 1