7-4 胎压监测 (15 分)

小轿车中有一个系统随时监测四个车轮的胎压,如果四轮胎压不是很平衡,则可能对行车造成严重的影响。

让我们把四个车轮 —— 左前轮、右前轮、右后轮、左后轮 —— 顺次编号为 1、2、3、4。本题就请你编写一个监测程序,随时监测四轮的胎压,并给出正确的报警信息。报警规则如下:

  • 如果所有轮胎的压力值与它们中的最大值误差在一个给定阈值内,并且都不低于系统设定的最低报警胎压,则说明情况正常,不报警;
  • 如果存在一个轮胎的压力值与它们中的最大值误差超过了阈值,或者低于系统设定的最低报警胎压,则不仅要报警,而且要给出可能漏气的轮胎的准确位置;
  • 如果存在两个或两个以上轮胎的压力值与它们中的最大值误差超过了阈值,或者低于系统设定的最低报警胎压,则报警要求检查所有轮胎。

输入格式:

输入在一行中给出 6 个 [0, 400] 范围内的整数,依次为 1~4 号轮胎的胎压、最低报警胎压、以及胎压差的阈值。

输出格式:

根据输入的胎压值给出对应信息:

  • 如果不用报警,输出 Normal
  • 如果有一个轮胎需要报警,输出 Warning: please check #X!,其中 X 是出问题的轮胎的编号;
  • 如果需要检查所有轮胎,输出 Warning: please check all the tires!

输入样例 1:

242 251 231 248 230 20

 

输出样例 1:

Normal

输入样例 2:

242 251 232 248 230 10

输出样例 2:

Warning: please check #3!

输入样例 3:

240 251 232 248 240 10

输出样例 3:

Warning: please check all the tires!

作者 陈越

单位 浙江大学

代码长度限制 16 KB

时间限制 400 ms

内存限制 64 MB

#include<stdio.h>
int main(){
	int i,A,B,C,D,lowest,yuzhi,MAX,count=0,a=0,b=0,c=0,d=0;
    scanf("%d %d %d %d %d %d",&A,&B,&C,&D,&lowest,&yuzhi);
		if(A>B && A>C && A>D)//判断四个轮胎胎压,找出最大的那个 
			MAX = A;
		else if(B>A && B>C && B>D)
			MAX = B;
		else if(C>A && C>B && C>D)
			MAX = C;
		else
			MAX = D;	
	if(MAX-A<=yuzhi && MAX-B<=yuzhi && MAX-C<=yuzhi && MAX-D<=yuzhi && A>=lowest && B>=lowest && C>=lowest && D>=lowest){
		printf("Normal");//先判断有无问题
	}
	if(MAX-A>yuzhi|| A < lowest)//有问题就标记count++,并且标记出问题的轮胎
		{
			count++;
			a = 1;
		}
	if(MAX-B>yuzhi|| B < lowest)
		{
			count++;
			b = 2;
		}
	if(MAX-C>yuzhi|| C < lowest)
		{
			count++;
			c = 3;
		}
	if(MAX-D>yuzhi|| D < lowest)	
		{
			count++;
			d = 4;
		}
		if(count >= 2){
		printf("Warning: please check all the tires!");
	}
	else if(count < 2 && count !=0){
		if(a==1){
			printf("Warning: please check #%d!",a);
		}
		else if(b==2){
			printf("Warning: please check #%d!",b);
		}
		else if(c==3){
			printf("Warning: please check #%d!",c);
		}else
			printf("Warning: please check #%d!",d);
		}
	
	
	
	return 0;
}
/*
#include <stdio.h>

int main(){
	int a,b,c,d,e,f,max;
	int count = 0;
	int m;
	int X;
	scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
	if(a>b && a>c && a>d)//判断四个轮胎胎压,找出最大的那个 
			max = a;
	else if(b>a && b>c && b>d)
			max = b;
		else if(c>a && c>b && c>d)
			max = c;
		else
			max = d;	
   
    	if(max-a>f || a<e){
    		X =1;
    		count++;
		}
		if(max-b>f || b<e){
			X =2;
			count++;
		}
		if(max-c>f || c<e){
			X =3;
			count++;
		}
		if(max-d>f || d<e){
			X =4;
			count++;
		} 
	
	if(count >= 2)
		printf("Warning: please check all the tires!");
	else if(count < 2 && count != 0)
		{
			if(X==1)
				printf("Warning: please check #%d!" ,X);
			else if(X==2)
				printf("Warning: please check #%d!" ,X);
			else if(X==3)
				printf("Warning: please check #%d!" ,X);
			else
				printf("Warning: please check #%d!" ,X);
		}
	else
		printf("Normal");
	return 0;
}*/

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值