PAT(乙级)1060 爱丁顿数(25 分)

注意审题。。。题目有一句话说的是存在即可

题目链接

#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;
}

猜你喜欢

转载自blog.csdn.net/curiousliu/article/details/81156742