团体程序设计天梯赛 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!

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        for (int i = 0; i < n; i++) {
            int H = input.nextInt();
            int W = input.nextInt();
            double standard=(H-100)*2*0.9;//标准体重
            if (Math.abs(W-standard)<standard*0.1) {//| 真实体重 − 标准体重 | < 标准体重×10%
                System.out.println("You are wan mei!");
            }
            else if ((W-standard)>=standard*0.1) {//(真实体重 − 标准体重 )> 标准体重×10%
                System.out.println("You are tai pang le!");
            }
            else{//(真实体重 − 标准体重 )<-标准体重×10%
                System.out.println("You are tai shou le!");
            }
        }
    }
}

了解到新的方法:
在这里插入图片描述
上面的输入存储不太美
虽然都是10分,但是下面就是更清晰。

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        String str[][]=new String[n][2];
        for(int i=0;i<n;i++){
            for(int j=0;j<2;j++){
                str[i][j]=input.next();
            }
        }

        for (int i = 0; i < n; i++) {
            double standard=(Integer.parseInt(str[i][0])-100)*2*0.9;//标准体重
            int weight=Integer.parseInt(str[i][1]);
            if (Math.abs(weight-standard)<standard*0.1) {//| 真实体重 − 标准体重 | < 标准体重×10%
                System.out.println("You are wan mei!");
            }
            else if ((weight-standard)>=standard*0.1) {//(真实体重 − 标准体重 )> 标准体重×10%
                System.out.println("You are tai pang le!");
            }
            else{//(真实体重 − 标准体重 )<-标准体重×10%
                System.out.println("You are tai shou le!");
            }
        }
    }
}

参考链接:
https://blog.csdn.net/Wdeadbug/article/details/90137416?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param
点击进入

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值