Hdu 2019, hdu
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 3 1 2 4 0 0 Sample Output1 2 3 4 # include <stdio. h>
Int main ()
{
Int n, m, I, j, temp, cnt;
Int str [101];
While (scanf ("% d", & n, & m )! = EOF ){
If (n = 0 & m = 0) return 0;
Else {
For (I = 0; I <n; I ++ ){
Scanf ("% d", & str [I]);
}
If (str [n-1] <= m) str [n] = m;
Else {
For (I = 0; I <n-1; I ++ ){
If (str [I] <m & str [I + 1]> = m ){
Cnt = I;
For (j = n + 1; j> cnt + 1; j --){
Str [j] = str [J-1];
}
Str [cnt + 1] = m;
}
}
}
For (I = 0; I <n + 1; I ++ ){
Printf ("% d", str [I]);
If (I <n) printf ("");
Else printf ("\ n ");
}
}
}
Return 0;
} Tip: Specifies the size of the array. It also determines the insertion position. The value is smaller than or equal to the first part, and the value is greater than or equal to the later part.