让我们把四个车轮 —— 左前轮、右前轮、右后轮、左后轮 —— 顺次编号为 1、2、3、4。本题就请你编写一个监测程序,随时监测四轮的胎压,并给出正确的报警信息。报警规则如下:
- 如果所有轮胎的压力值与它们中的最大值误差在一个给定阈值内,并且都不低于系统设定的最低报警胎压,则说明情况正常,不报警;
- 如果存在一个轮胎的压力值与它们中的最大值误差超过了阈值,或者低于系统设定的最低报警胎压,则不仅要报警,而且要给出可能漏气的轮胎的准确位置;
- 如果存在两个或两个以上轮胎的压力值与它们中的最大值误差超过了阈值,或者低于系统设定的最低报警胎压,则报警要求检查所有轮胎。
- 代码如下:
-
#include<bits/stdc++.h>
using namespace std;
struct car {
int num;
int p;
int min;
int cha;
} a[10086];
bool cmp(car x,car y)
{
return x.p<y.p;
}
int main() {
for (int i = 1; i <= 4; i++) {
cin >> a[i].p;
a[i].num = i;
}
sort(a + 1, a + 1 + 4,cmp);
cin >> a[5].min >> a[6].cha;
if (a[4].p - a[2].p > a[6].cha || a[2].p < a[5].min)
{
cout << "Warning: please check all the tires!" << endl;
}
else if (a[4].p - a[1].p > a[6].cha || a[1].p < a[5].min)
{
cout << "Warning: please check #" << a[1].num << "!" << endl;
}
else {
cout << "Normal" << endl;
}
return 0;
}