关键词:
排序 查找
题目:
解决方法:
1 package package1; 2 3 import java.util.Scanner; 4 5 6 public class test { 7 8 public static void main(String[] args) { 9 Scanner in = new Scanner(System.in ); 10 int n = in.nextInt(); 11 int A[] = new int[n]; 12 //输入序列 13 for (int i = 0; i < n; i++) { 14 A[i] = in.nextInt(); 15 } 16 //输出循环次数 17 int m = in.nextInt(); 18 int output[] = new int[m]; 19 20 //输入L,R,K 21 for (int i = 0; i < m; i++) { 22 int l = in.nextInt(); 23 int r = in.nextInt(); 24 int k = in.nextInt(); 25 26 int K[] = new int[r - l + 1]; 27 28 29 for (int j = l - 1; j < r; j++) { 30 K[j + 1 - l] = A[j]; 31 } 32 33 //排序 34 for (int j = 0; j < K.length; j++) { 35 for (int j1 = j; j1 < K.length; j1++) { 36 if(K[j1]>K[j]){ 37 int swap = K[j1]; 38 K[j1]= K[j]; 39 K[j] = swap; 40 } 41 } 42 } 43 44 output[i] = K[k-1]; 45 } 46 47 for (int i = 0; i < m; i++) { 48 System.out.println(output[i]); 49 } 50 } 51 }