1060 爱丁顿数 (C++)

英国天文学家爱丁顿很喜欢骑车。据说他为了炫耀自己的骑车功力,还定义了一个“爱丁顿数” E ,即满足有 E 天骑车超过 E 英里的最大整数 E。据说爱丁顿自己的 E 等于87。

现给定某人 N 天的骑车距离,请你算出对应的爱丁顿数 E(≤N)。

输入格式:

输入第一行给出一个正整数 N (≤105),即连续骑车的天数;第二行给出 N 个非负整数,代表每天的骑车距离。

输出格式:

在一行中给出 N 天的爱丁顿数。

输入样例:

10
6 7 6 9 3 10 8 2 7 8

结尾无空行

输出样例:

6

结尾无空行

代码:

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int n,temp,i;
    cin >>n;
    vector<int> mark;
    for(i=0;i<n;i++){
        cin >>temp;
        mark.push_back(temp);
    }
    sort(mark.rbegin(),mark.rend());
    for(i=0;i<n;i++){
        if(mark[i]<=i+1){
            break;
        }
    }
    cout <<i<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40748967/article/details/121383621