A. Olympiad

此文章介绍了一个关于Berland Olympiad in Informatics的编程问题解决方案,该问题要求确定获得奖状的参赛者组合数量。文章提供了一个C语言程序,通过排序参赛者的分数并考虑特定条件来解决这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Olympiad
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.

As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:

At least one participant should get a diploma.
None of those with score equal to zero should get awarded.
When someone is awarded, all participants with score not less than his score should also be awarded.
Determine the number of ways to choose a subset of participants that will receive the diplomas.

Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of participants.

The next line contains a sequence of n integers a1, a2, …, an (0 ≤ ai ≤ 600) — participants’ scores.

It’s guaranteed that at least one participant has non-zero score.

Output
Print a single integer — the desired number of ways.

Examples
inputCopy
4
1 3 3 2
outputCopy
3
inputCopy
3
1 1 1
outputCopy
1
inputCopy
4
42 0 0 42
outputCopy
1
Note
There are three ways to choose a subset in sample case one.

Only participants with 3 points will get diplomas.
Participants with 2 or 3 points will get diplomas.
Everyone will get a diploma!
The only option in sample case two is to award everyone.

Note that in sample case three participants with zero scores cannot get anything.

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n,i,t,j;
    int a[101];
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0; i<n; i++)
    {
        for(j=0; j<n-i-1; j++)
        {
            if(a[j+1]>a[j])
            {
                t=a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
        }
    }
    int sum=1;
    for(i=1; i<n;)
    {
        if(a[i])
        {
            if(a[i]==a[i-1])i++;
            else
            {
                sum++;
                i++;
            }
        }
        else i++;
    }
    printf("%d\n",sum);
    return 0;
}

如果是0的话肯定是没有奖项的,只要是不为0的数就要算进去,相同的算作一个数,i++跳过就行,主要考for循环吧,如何跳过相同的数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值