L1-069 胎壓監(jiān)測 (15 分)
L1-069 胎壓監(jiān)測 (15 分)
小轎車中有一個(gè)系統(tǒng)隨時(shí)監(jiān)測四個(gè)車輪的胎壓,如果四輪胎壓不是很平衡,則可能對行車造成嚴(yán)重的影響。

讓我們把四個(gè)車輪 —— 左前輪、右前輪、右后輪、左后輪 —— 順次編號為 1、2、3、4。本題就請你編寫一個(gè)監(jiān)測程序,隨時(shí)監(jiān)測四輪的胎壓,并給出正確的報(bào)警信息。報(bào)警規(guī)則如下:
如果所有輪胎的壓力值與它們中的最大值誤差在一個(gè)給定閾值內(nèi),并且都不低于系統(tǒng)設(shè)定的最低報(bào)警胎壓,則說明情況正常,不報(bào)警;
如果存在一個(gè)輪胎的壓力值與它們中的最大值誤差超過了閾值,或者低于系統(tǒng)設(shè)定的最低報(bào)警胎壓,則不僅要報(bào)警,而且要給出可能漏氣的輪胎的準(zhǔn)確位置;
如果存在兩個(gè)或兩個(gè)以上輪胎的壓力值與它們中的最大值誤差超過了閾值,或者低于系統(tǒng)設(shè)定的最低報(bào)警胎壓,則報(bào)警要求檢查所有輪胎。
輸入格式:
輸入在一行中給出 6 個(gè) [0, 400] 范圍內(nèi)的整數(shù),依次為 1~4 號輪胎的胎壓、最低報(bào)警胎壓、以及胎壓差的閾值。
輸出格式:
根據(jù)輸入的胎壓值給出對應(yīng)信息:
如果不用報(bào)警,輸出
Normal;如果有一個(gè)輪胎需要報(bào)警,輸出
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!
代碼:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,a[4],p,q,cnt=0,b[4]={0},Max=-1;
for(i=0;i<4;i++)
{
cin>>a[i];
Max = max(Max,a[i]);
}
scanf("%d %d",&p,&q);
for(i=0;i<4;i++)
{
if(a[i]<p)
b[i]++;
if(Max-a[i]>q)
b[i]++;
}
for(i=0;i<4;i++)
{
if(b[i]!=0)
cnt++;
}
if(cnt>=2)
printf("Warning: please check all the tires!");
else if(cnt == 1)
{
for(i=0;i<4;i++)
{
if(b[i]!=0)
{
printf("Warning: please check #%d!",i+1);
break;
}
}
}
else
printf("Normal");
}
代碼:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
int maxx = max(a, max(b, max(c, d)));
if(maxx - a > f || a < e)
a = -1;
else
a = 0;
if(maxx - b > f || b < e)
b = -1;
else
b = 0;
if(maxx - c > f || c < e)
c = -1;
else
c = 0;
if(maxx - d > f || d < e)
d = -1;
else
d = 0;
if(a + b + c + d == 0)
cout << "Normal" << endl;
else if(a + b + c + d < -1)
cout << "Warning: please check all the tires!" << endl;
else
{
cout << "Warning: please check #";
if(a == -1)
cout << "1";
else if(b == -1)
cout << "2";
else if(c == -1)
cout << "3";
else
cout << "4";
cout << "!" << endl;
}
return 0;
}
