L1-069 Tire pressure monitoring (15 points)

There is a system in the car that monitors the tire pressure of the four wheels at any time. If the four tire pressures are not very balanced, it may have a serious impact on the driving.

Let's number the four wheels-left front wheel, right front wheel, right rear wheel, left rear wheel-in sequence as 1, 2, 3, 4. For this question, please write a monitoring program to monitor the tire pressure of the four wheels at any time and give the correct alarm information. The alarm rules are as follows:

If the error between the pressure value of all tires and the maximum value of them is within a given threshold, and is not lower than the minimum alarm tire pressure set by the system, it means that the situation is normal and no alarm;
if there is a tire pressure value and If the maximum error among them exceeds the threshold or is lower than the minimum alarm tire pressure set by the system, not only the alarm is required, but also the exact location of the tire that may leak;
if there are two or more tires If the error between the pressure value and the maximum of them exceeds the threshold, or is lower than the minimum alarm tire pressure set by the system, the alarm requires checking all tires.
Input format:
Enter 6 integers in the range of [0, 400] in a row, which are the tire pressure of tires No. 1 to 4, the lowest alarm tire pressure, and the threshold value of tire pressure difference.

Output format:
give corresponding information according to the input tire pressure value:

If there is no alarm, output Normal;
if there is a tire that needs to be alarmed, output Warning: please check #X!, where X is the number of the tire in question;
if you need to check all tires, output Warning: please check all the tires!.
Input example 1:
242 251 231 248 230 20
Output example 1:
Normal
Input example 2:
242 251 232 248 230 10
Output example 2:
Warning: please check #3!
Input example 3:
240 251 232 248 240 10
Output sample 3:
Warning: please check all the tires!

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int a[10],b,c,maxn=0;
	for(int i=1;i<=4;i++)
	{
    
    
		cin>>a[i];
		maxn=max(maxn,a[i]);
	}
	cin>>b>>c;
	int ans=0,x;
	for(int i=1;i<=4;i++)
	 if(a[i]<b||(maxn-a[i])>c)
	 {
    
    
	 	ans++;x=i;
	 }
	if(ans==0) cout<<"Normal";
	else if(ans==1) cout<<"Warning: please check #"<<x<<"!";
	else cout<<"Warning: please check all the tires!";
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_43540515/article/details/112978058