注意审题。。。题目有一句话说的是存在即可
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <cmath>
#include <cstdlib>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int n;
scanf("%d",&n);
int a[100005];
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(int i=n;i>=0;i--)
{
int count = 0;
for(int j=0;j<n;j++)
{
if(a[j]>i)
{
count ++;
}
}
if(count >= i)
{
printf("%d\n",i);//阴题。。 注意题目里的有 存在即可。。。
return 0;
}
}
//system("pause");
return 0;
}
本文介绍了一道算法题目,主要关注如何通过遍历数组并进行条件判断来找到满足特定条件的最大整数。该算法使用了简单的遍历和计数方法,并在满足题目要求的情况下尽早返回结果。
4993





