编程题:27
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int K = scanner.nextInt();
int[] arr = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = scanner.nextInt();
}
for (int i = 0; i < K; i++) {
for (int j = 0; j < N - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
for (int i = 0; i < N; i++) {
if (i > 0) {
System.out.print(" ");
}
System.out.print(arr[i]);
}
}
}
浙公网安备 33010602011771号