PAT A-1117 Eddington Number (25 points)

Title: 1117 Eddington Number (25 points)
Analysis : Sort from largest to smallest, find the first number of days whose mileage is less than or equal to i, that is, the i-th day is the answer (I didn’t understand what it means when I read the question, rubbish question ┭┮﹏┭┮, hateful)
#include <iostream>
#include<cstring>
#include<vector>
#include<map>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define MAX 999999999
int n,m;
int main()
{
    
    
    cin>>n;
    int a[n+1];
    for(int i = 0 ; i < n ; i++)
        cin>>a[i];
    sort(a,a+n,greater<int>());
    int i;
    for(i = 0; i < n ;i++)
        if(a[i] <= i + 1) break;
    cout<<i;
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_43567222/article/details/113915510
Recommended