码迷,mamicode.com
首页 > 其他好文 > 详细

杭电ACM2019--数列有序!

时间:2019-01-13 00:19:39      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:while   ota   输出   rip   acm   for   sam   can   turn   

数列有序!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 122510    Accepted Submission(s): 50550


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
 
 
顾题思意~
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int n,a[101],i,temp,m,j;
 5     while(~scanf("%d%d",&n,&m)&&n&&m)
 6     {
 7         for(i=0;i<n;i++)
 8             scanf("%d",&a[i]);
 9         a[i]=m;
10         for(i=0,j=n;i<n+1;i++)
11             if(a[i]>a[j])
12             {
13                 temp=a[i];
14                 a[i]=a[j];
15                 a[j]=temp;
16             }
17         printf("%d",a[0]);
18         for(i=1;i<=n;i++)
19             printf(" %d",a[i]);
20         printf("\n");
21     }
22     return 0;
23 }

 

杭电ACM2019--数列有序!

标签:while   ota   输出   rip   acm   for   sam   can   turn   

原文地址:https://www.cnblogs.com/lightice/p/10261275.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!