[title description]
Care unit measured every hour in the patient's blood pressure, if the systolic and diastolic blood pressure between 90-140 (including the endpoint value) between 60-90 refer to it as normal, now give a patient several measuring blood pressure value, calculate the patient to maintain normal blood pressure of the longest hours,
[enter]
The first act a positive integer n (n<100), followed by n lines, each line of two positive integers, respectively measured systolic and diastolic blood pressure at a time,
[output]
Output is only a line, the longest hours, continuous normal blood pressure
[input sample]
4
100, 80,
50 90
60 120
140, 90,
[output sample]
2
My program is as follows:
# include & lt; Cstdio>
using namespace std;
Int main ()
{
Int hour, systolic and diastolic, last_keep=0, next_keep=0, not_normal=0;
Hours/definition/hour, systolic systolic pressure, diastolic blood pressure, last_keep and next_keep hours and hours not_normal abnormal integer variables
The scanf (" % d ", & amp; Hour);//the number of hours the scanf input
for (int i=1; I & lt;=hour; + + I)//use a for loop to let user input hour time blood pressure
{
The scanf (" % d % d ", & amp; Systolic, & amp; Diastolic);//the scanf input systolic and diastolic blood pressure
If ((90 & lt;=systolic) & amp; & (systolic & lt;=140) & amp; & (60 & lt;=diastolic) & amp; & (diastolic & lt;=90))//whether blood pressure normal
{
If (not_normal==0)//whether blood pressure still hasn't been normal
{
Last_keep +=1;//hours (not normal) before 1
}
The else//it is not normal blood pressure
{
Next_keep +=1;//(abnormal) after hours to keep 1
If (next_keep & gt; Last_keep)//whether new hours to keep the record
{
Last_keep=next_keep;//update the record, no matter in front of the keep in a row, with this new record for the new starting point to continue
Next_keep=0;//update the standard after zero
Not_normal=0;//update the standard after zero
}
}
}
The else//not normal blood pressure
{
If (not_normal==0)//judgment is not normal for the first time
{
Not_normal +=1;//not normal times add 1
}
}
}
Printf (" % d \ n ", last_keep);//printf output the longest record
return 0;//end program
}
The book has a matching evaluation website, http://ybt.ssoier.cn:8088/, I hand up the program after it says wrong answer, I wonder , look at the book reference answer, refer to the answer is as follows:
#include
using namespace std;
Int main ()
{
Int a, b, I, n, t, m, j, Max=0;//Max store hours longest continuous normal blood pressure patients
The scanf (" % d ", & amp; n); t=0;
For (I=1; I<=n; + + I)//cycle to judge each hour, the patient's blood pressure is normal
{
The scanf (" % d % d ", & amp; A, & amp; B);
If (a>=90 & amp; & A<=140 & amp; & B>=60 & amp; & B
=90)//judgment in the I in the hours, the patient's blood pressure is normal
{
t++;
If (t> Max) Max=t;
}
The else t=0;//the patient's blood pressure is not normal, then reset t
}
Printf (" % d \ n ", Max).
return 0;
}
I wonder after see , where is my program is wrong?
Ask your bosses teach teach!!!!!! Thank you!!!!!! Thank you very much!!!!!!
CodePudding user response:
Can you say something about your logic didn't look, this is a rather simple topic how to write so complicated