解题思路:
注意事项:
参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { int n = scanner.nextInt(); int m = scanner.nextInt(); if (n == 0 && m == 0) { break; } boolean inserted = false; // 标记是否已插入新元素 for (int i = 0; i < n; i++) { int temp = scanner.nextInt(); // 插入新元素的逻辑 if (!inserted && temp > m) { System.out.print(m + " "); inserted = true; } System.out.print(temp + " "); } // 如果新元素应插入到数列末尾 if (!inserted) { System.out.print(m); } System.out.println(); // 换行 } } }
0.0分
0 人评分