#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int temp;
scanf("%d", &temp);
int min=temp;
int max=temp;
int Count=0;
while(--n)
{
scanf("%d", &temp);
if(temp>max)
{
++Count;
max=temp;
}
else if(temp<min)
{
++Count;
min=temp;
}
}
printf("%d\n", Count);
return 0;
}
@将每组数据的一个数据作为变量min和max的初始值,然后从第二个数据开始将其与变量max和min比较,如果比最大值大,则变量max被赋值为当前数据,并将变量Count加一;如果当前数据的值比最小值还要小,则将变量min的值改为当前值,同样将变量Count加一,对这组数据中的余下数据依次做上述比较,直到整组数据比较结束。此时,变量Count的值即为Answer。
posted on
浙公网安备 33010602011771号