编程题:30
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();
scanner.nextLine();
String[] strings = new String[N];
for (int i = 0; i < N; i++) {
strings[i] = scanner.nextLine();
}

    for (int i = 0; i < K; i++) {
        for (int j = 0; j < N - 1 - i; j++) {
            if (strings[j].compareTo(strings[j + 1]) > 0) {
                String temp = strings[j];
                strings[j] = strings[j + 1];
                strings[j + 1] = temp;
            }
        }
    }

    for (String s : strings) {
        System.out.println(s);
    }
}

}

posted on 2025-05-19 23:51  Swishy  阅读(7)  评论(0)    收藏  举报