HDOJ2019
2017-09-26 22:57
525 查看
Problem Description
有n(n<=100)个整数,已经按照从小到大顺序排列好,现在另外给一个整数x,请将该数插入到序列中,并使新的序列仍然有序。
Input
输入数据包含多个测试实例,每组数据由两行组成,第一行是n和m,第二行是已经有序的n个数的数列。n和m同时为0标示输入数据的结束,本行不做处理。
Output
对于每个测试实例,输出插入新的元素后的数列。
Sample Input
3 3
1 2 4
0 0
Sample Output
1 2 3 4
有n(n<=100)个整数,已经按照从小到大顺序排列好,现在另外给一个整数x,请将该数插入到序列中,并使新的序列仍然有序。
Input
输入数据包含多个测试实例,每组数据由两行组成,第一行是n和m,第二行是已经有序的n个数的数列。n和m同时为0标示输入数据的结束,本行不做处理。
Output
对于每个测试实例,输出插入新的元素后的数列。
Sample Input
3 3
1 2 4
0 0
Sample Output
1 2 3 4
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); int x = sc.nextInt(); if(n==0&&x==0)break; boolean flag = true; while(n-->0){ int y = sc.nextInt(); if(x<y&&flag){ System.out.print(x+" "+y); flag = false; }else{ System.out.print(y); } if(n!=0){ System.out.print(" "); } } System.out.println(); } } }
相关文章推荐
- hdoj2019 数列有序!
- HDOJ 2019 数列有序!(排序)
- HDOJ 2019 用链表插入试试
- HDOJ 2019 数列有序!
- Hdoj2019_数列有序!
- (HDOJ2019)数列有序!
- HDOJ 2019 数列有序!
- HDOJ2019 数列有序!
- HDOJ2019 数列有序
- HDOJ water 2019
- hdoj_2019 数列有序!
- HDOJ 2019
- hdoj 2019(java)数列有序!(数组+for循环 ;i<n;i++)
- HDOJ 2019 数列有序!
- HDOJ2019
- HDOJ2019 数列有序
- HDOJ2019 ( 数列有序! ) 【水题】
- HDOJ2019
- java 杭电hdoj2019题 求优化
- HDOJ--2019