解题思路:
import java.util.Scanner; public class C1220 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(), m = sc.nextInt(); if(n == 0 && m == 0) break; int[] a = new int[n+1]; for(int i = 0; i < n; i++){ a[i] = sc.nextInt(); } //插入数字m for(int i = n-1; i >= 0; i--){ if(a[i] > m){ a[i+1] = a[i]; }else{ a[i+1] = m; break; } } //打印数组 for(int i = 0; i <= n; i++){ if(i < n) System.out.printf("%d ", a[i]); else System.out.printf("%d\n", a[i]); } } sc.close(); } }
注意事项:
参考代码:
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:756 |
兰顿蚂蚁 (C++代码)浏览:1045 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:857 |
【绝对值排序】 (C语言代码)浏览:821 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:542 |
前10名 (C语言代码)浏览:727 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:546 |
买不到的数目 (C语言代码)浏览:3094 |
快速排序算法1浏览:884 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:598 |