# Hangzhou (Hangzhou), 2019 20:49:34

Source: Internet
Author: User
Sequence!

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 46658 accepted submission (s): 20141

Problem description has n (n <= 100) integers, which have been arranged in ascending order. Now, to add an integer x, insert the number into the sequence, and make the new sequence still orderly.

The input data contains multiple test instances. Each group of data consists of two rows. The first row is N and M, and the second row is a series of ordered n numbers. If n and m are both 0, the end of the input data is indicated. We will not process the data.

For each test instance, output is the sequence after the new element is inserted.

Sample input3 31 2 40 0

Sample output1 2 3 4
` 1 #include<cstdio> 2 int main() 3 { 4     int n,m,a[100]={0}; 5     while(scanf("%d%d",&n,&m)!=EOF) 6     { 7         if(n==0&&m==0)return 0; 8         for(int i=0;i<n;i++)scanf("%d",&a[i]); 9         a[n]=m;10         for(int i=0;i<n;i++)11             for(int j=i+1;j<=n;j++)12                 if(a[i]>a[j]){m=a[i];a[i]=a[j];a[j]=m;}13 14         for(int i=0;i<n;i++)printf("%d ",a[i]);15         printf("%d\n",a[n]);16     }17 }`

Hangzhou (Hangzhou), 2019 20:49:34

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.