蓝桥杯 入门训练 Fibonacci数列 JAVA
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int a = s.nextInt();
int b[] = new int[a];
for (int i = 0; i < b.length; i++) {
b[i]=s.nextInt();
}
int c =s.nextInt();
int g[] = new int[c];
int h=0;
while(c>0){
int d =s.nextInt();
int e =s.nextInt();
int f[]=new int[e-d+1];
for (int i = 0; i < f.length; i++) {
f[i]=b[d-1+i];
}
Arrays.sort(f);
g[h]=f[f.length-s.nextInt()];
c--;
h++;
}
for (int i = 0; i < g.length; i++) {
System.out.println(g[i]+"");
}
}
}
本文介绍了一个基于蓝桥杯竞赛的Fibonacci数列编程练习题目的Java实现。该程序读取输入数据,包括一系列整数及其查询范围,并对指定范围内的一组Fibonacci数进行排序,最后输出指定位置上的数。此代码适用于初学者理解数组操作、排序及Fibonacci数列的计算。
554

被折叠的 条评论
为什么被折叠?



