[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;
}