找出第3名学生的成绩

题目出处:桂电oj,网址:http://onlinejudge.guet.edu.cn/guetoj/problem/1030.html

Description

计算机创新工程训练基地进行完招新开始后,想知道本次考试第3名学生的成绩是多少?
如果最高分有好多个学生,则相同成绩的学生都算第一名;同理,如果第二高分的有多个学生,都算第二名。
当然这是简单题,请你快速编一个程序找到第3名的成绩。

Input

输入:输入有一组,每组有2行,第一行是学生人数N(1<=N<1000),第二行有N个整数,分别表示每个学生的成绩(0到150)。

Output

输出:对于每组输入,输出只有一行,即第3名学生的成绩,如果找不到,则输出No such score !

Sample Input

10
90 84 90 60 70 65 73 85 98 98

5
90 90 89 90 90


Sample Output

85

No such score !

//----------------------------------------------------------------------------------------

#include <iostream>
using namespace std;
int judge(int b,int a[]);
int c = 0;
int main()
{
    int score [150];
    int a;
    cin >> a;
    for (int i = 0; i < a; i++)
    {
        cin >> score[i];
    }
    if (judge(a,score) == 1)
    {
        cout << score[c];
    }
    else
    {
        cout << "No such score ! ";
    }
    return 0;
}
int judge(int b,int a[])
{
    int n = 3;
    for (int i = 0; i < b; i++)
    {
        for (int j = b - 1; j > i; j--)
        {
            if (a[j] > a[j-1])
            {
                    int tmp = a[j];
                    a[j] = a [j-1];
                    a[j-1] = tmp;
            }
        }
    }
   for (int i = 0; i < b; i++)
    {
        if (a[i] != a[i+1])
        {
            n--;
        }
        if (n == 0)
        {
            c = i;
            return 1;
        }
    }
    return 0;
}

原文地址:https://www.cnblogs.com/ediszhao/p/3481429.html