L1-069 胎压监测(15 分)

一、题目

二、解题思路

  1. 找出最大值、最小值、超过阈值的数量、低于最低报警胎压的数量;
  2. 如果 (minn>ban && (maxx-minn)<=dif) ,输出 Normal ;
  3. 如果 ((cot1==1 || cot2==1) && (cot1<2 && cot2<2)) ,即只有胎压最低的轮胎需要报警,找出此轮胎的序号,输出 Warning: please check #%d! ;
  4. 否则需要检查所有轮胎,输出 Warning: please check all the tires! 。

三、代码

#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d,ban,dif;
	cin>>a>>b>>c>>d>>ban>>dif;
	int minn=min(min(a,b),min(c,d));
	int maxx=max(max(a,b),max(c,d));
	int cot1 = (maxx-a>dif)+(maxx-b>dif)+(maxx-c>dif)+(maxx-d>dif);
	int cot2 = (a<ban)+(b<ban)+(c<ban)+(d<ban);
	if(minn>ban && (maxx-minn)<=dif)
	{
		cout<<"Normal";
	}
	else if((cot1==1 || cot2==1) && (cot1<2 && cot2<2)) 
	{
		int x;
		if(minn==a)
		{
			x=1;
		}
		else if(minn==b)
		{
			x=2;
		}
		else if(minn==c)
		{
			x=3;
		}
		else
		{
			x=4;
		}
		printf("Warning: please check #%d!",x);
	}
	else
	{
		cout<<"Warning: please check all the tires!";
	}
}

四、总结

  1. 超过阈值的数量:cot1 = (maxx-a>dif)+(maxx-b>dif)+(maxx-c>dif)+(maxx-d>dif) 。
  2. 低于最低报警胎压的数量:cot2 = (a<ban)+(b<ban)+(c<ban)+(d<ban) 。
  • 12
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值