2019——数列有序
2014-01-29 21:06
309 查看
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
#include <stdio.h> #include <stdlib.h> main() { int n,x,*p; while(scanf("%d %d",&n,&x)!=EOF && (n||x)) { int i,j,flag=0; p=(int *)calloc(n,sizeof(int)); for(i=0;i<n;i++) scanf("%d",&p[i]); for(i=0;i<n;i++) if(x<p[i]) {j=i-1;break;} if(j<n-1) {for(i=0;i<=j;i++) printf("%d ",p[i]); printf("%d ",x); for(i=j+1;i<n-1;i++) printf("%d ",p[i]); printf("%d\n",p[n-1]); } else {for(i=0;i<n;i++) printf("%d ",p[i]); printf("%d\n",x); } } }
不能发了=_=
本来准备今天整理完的
战高数去了
相关文章推荐
- hduoj 2019数列有序
- HDOJ 2019 数列有序!
- hdoj-2019 数列有序!【水】
- HDU 2019 数列有序 (water)
- C++ hdoj 2019 数列有序
- 2019 数列有序!
- 好的 2019 数列有序!
- <HDU 2019> 数列有序!
- HDU 2019 数列有序!
- HDU - 2019 数列有序!
- hdu-2019-数列有序!
- hdoj 2019(java)数列有序!(数组+for循环 ;i<n;i++)
- 杭电 acm 2019 数列有序
- hdu 2019 数列有序!
- HDOJ 2019 数列有序!
- HDU 2019 数列有序!
- 杭电2019 数列有序!
- hdu 2019 数列有序!
- 杭电2019 数列有序!
- HDOJ2019 数列有序