Question one hundred and three: sequence of numbers!

Source: Internet
Author: User

[Plain] Description
 
There are n (n <= 100) integers, which have been arranged in ascending order. Now we also provide an integer m. Please insert this number into the sequence, and make the new sequence still orderly.
 
Input
 
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.
 
Output
 
For each test instance, the sequence after inserting new elements is output.
 
Sample Input
 
 
3 3
1 2 4
0 0
 
Sample Output
 
 
1 2 3 4

Description

There are n (n <= 100) integers, which have been arranged in ascending order. Now we also provide an integer m. Please insert this number into the sequence, and make the new sequence still orderly.

Input

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.

Output

For each test instance, the sequence after inserting new elements is output.

Sample Input


3 3
1 2 4
0 0

Sample Output


1 2 3 4
[Plain] # include <stdio. h>
 
Int main ()
{
Int I;
Int j;
Int k;
Int n;
Int m;
Int t;
Int num [100];
 
While (scanf ("% d", & n, & m )! = EOF, n! = 0 | m! = 0)
{
For (k = 0; k <n; k ++)
{
Scanf ("% d", & num [k]);
}
Num [k ++] = m;
 
For (I = 0; I <K-1; I ++)
{
For (j = I + 1; j <k; j ++)
{
If (num [I]> num [j])
{
T = num [I];
Num [I] = num [j];
Num [j] = t;
}
}
}
For (I = 0; I <k; I ++)
{
Printf ("% d", num [I]);
If (I <k-1)
{
Printf ("");
}
}
 
Printf ("\ n ");
}
Return 0;
}

# Include <stdio. h>

Int main ()
{
Int I;
Int j;
Int k;
Int n;
Int m;
Int t;
Int num [100];

While (scanf ("% d", & n, & m )! = EOF, n! = 0 | m! = 0)
{
For (k = 0; k <n; k ++)
{
Scanf ("% d", & num [k]);
}
Num [k ++] = m;

For (I = 0; I <K-1; I ++)
{
For (j = I + 1; j <k; j ++)
{
If (num [I]> num [j])
{
T = num [I];
Num [I] = num [j];
Num [j] = t;
}
}
}
For (I = 0; I <k; I ++)
{
Printf ("% d", num [I]);
If (I <k-1)
{
Printf ("");
}
}

Printf ("\ n ");
}
Return 0;
}

 


 


Related Article

Contact Us

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.