L1-031 到底是不是太胖了 (10 分)
据说一个人的标准体重应该是其身高(单位:厘米)减去100、再乘以0.9所得到的公斤数。真实体重与标准体重误差在10%以内都是完美身材(即 | 真实体重 − 标准体重 | < 标准体重×10%)。已知市斤是公斤的两倍。现给定一群人的身高和实际体重,请你告诉他们是否太胖或太瘦了。
输入格式:
输入第一行给出一个正整数N(≤ 20)。随后N行,每行给出两个整数,分别是一个人的身高H(120 < H < 200;单位:厘米)和真实体重W(50 < W ≤ 300;单位:市斤),其间以空格分隔。
输出格式:
为每个人输出一行结论:如果是完美身材,输出You are wan mei!;如果太胖了,输出You are tai pang le!;否则输出You are tai shou le!。
输入样例:
3
169 136
150 81
178 155
输出样例:
You are wan mei!
You are tai shou le!
You are tai pang le!
注意那个上下浮动10% 就是乘0.1 不要想多了
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int n, h, w;
double biao;
scanf("%d", &n);
while(n--)
{
scanf("%d %d", &h, &w);
biao = (h - 100) * 1.8;
//printf("%f\n", biao);
double p;
if(w > biao)
{
p = w - biao;
}else{
p = biao - w;
}
double q = 0.1 * biao;
if(p < q)
{
printf("You are wan mei!\n");
}
else if(w < biao)
{
printf("You are tai shou le!\n");
}
else
{
printf("You are tai pang le!\n");
}
}
return 0;
}
这个地方注意 abs 返回整形数据的绝对值 浮点型就用fabs。
头文件:#include<math.h>
用 法: int abs(int i);
fabs 返回浮点数据的绝对值。
头文件:#include <math.h>
用法:extern float fabs(float x);
求绝对值的数据类型是整形就用abs,是浮点型就用fabs。
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
for(int i = 0; i < n; i++) {
float height, weight;
cin >> height >> weight;
float stan = (height - 100) * 0.9 * 2;
if(fabs(stan - weight) < stan * 0.1) {
cout << "You are wan mei!" << endl;
} else if(stan > weight) {
cout << "You are tai shou le!" << endl;
} else {
cout << "You are tai pang le!" << endl;
}
}
return 0;
}
本文介绍了一种根据身高和体重评估体型的算法,通过计算标准体重并对比实际体重,判断个体是否偏瘦、完美或过胖。算法使用身高减100再乘以0.9作为标准体重,误差范围设定为10%,并提供了C++实现代码。
975

被折叠的 条评论
为什么被折叠?



