问题描述:
英国天文学家爱丁顿很喜欢骑车。据说他为了炫耀自己的骑车功力,还定义了一个“爱丁顿数” 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
代码:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// Scanner sc = new Scanner(System.in);
// int n =sc.nextInt();
String s = br.readLine();
int n = Integer.parseInt(s);
String[] mile = br.readLine().split(" ");
int max=n;
while(max>0) {
int cnt = 0;
for(int j=0;j<n;j++) {
if(Integer.parseInt(mile[j])>max) {
cnt++;
}
}
if(cnt>=max) {
break;
}
max--;
}
System.out.println(max);
}
}
结果: