I_love_%username%

原题连接:I_love_%username% - 洛谷

题目描述

Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.

One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).

Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.

输入格式

The first line contains the single integer nn ( 1<=n<=10001<=n<=1000 ) — the number of contests where the coder participated.

The next line contains nn space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 1000010000 .

输出格式

Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.

题意翻译

Vasya很喜欢一个coder,他喜欢看那个coder的节目,那个coder每次编程可以得到一个非负分数(不超过10000),而有两种情况能使Vasya惊讶: ·coder得到的分数完全大于过去的分数; ·coder得到的分数完全小于过去的分数。 注意:第一次得到的分数不会使人惊讶。 给定coder编程次数n,给定每次编程得到的分数,请你求出Vasya的惊讶次数。

看着题面上好像没有介绍输入输出和数据范围就来多嘴一句

输入输出格式

输入格式:

第一行包括一个整数n(1<=n<=1000),代表coder参加比赛时的编码数量;

第二行包括了n个用空格分开的整数,即coder每一个编码在比赛中的得分(得分均不超过10000);

输出格式:

输出一行,包括一个整数,代表整场比赛中Vasya被coder惊讶到的总次数;

由 @strike 提供翻译

输入输出样例

输入

5
100 50 200 150 200
 

输出 

2

输入

10
4664 6496 5814 7010 5762 5736 6944 4850 3698 7242

输出 #2复制

4

说明/提示

In the first sample the performances number 2 and 3 are amazing.

In the second sample the performances number 2, 4, 9 and 10 are amazing.

解题思路

Vasya得分的时候会和自己以往的分数进行比较,若是刷出了min或者max,就会惊讶一次。

所以,可将Vasya的m个分数放到数组n[m]中,设max,min都是n[0]。不断向数组中输入新的成绩,若比min小或者比max大,则同步更新他们的值,惊讶次数(count)+1;

代码

#include<stdio.h>
int main(){
	int max,min,i,count=0;//count惊讶次数
	int num;
	scanf("%d",&num);
	int score[num];
	scanf("%d",&score[0]);
	max=min=score[0];//因为第一次不会惊讶,所以单独赋值,设min,max都为score[0]
	for(i=1;i<num;i++){
		scanf("%d",&score[i]);
		if(score[i]>max){//比以往都大的max出现,更新value,次数+1
			count++;
			max=score[i];
		}
		if(score[i]<min){//同理,比之前都小的值出现
			count++;
			min=score[i];
		}
	}
	printf("%d",count);//输出惊讶次数
	
	
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值