codeup exercises 6-4

Title Description

After the array row has a good sequence, requires a number of inputs, ordered according to the law of the original insert it into the array.

Suppose the length of the array 10, the array number of the first nine (9 number which requires input from the keyboard, to input brought to meet a large input order) has been sorted in ascending.

Input from the keyboard and then an integer, the integer number 9 is inserted into this order in the front, so that the final number of 10 is still ordered from small to large.

Entry

The first line of the input number 9 integers separated by spaces, in order from small to large requires input.

A second line of the input integer

Export

This small to large output number 10, the number of each row.

Sample input

1 11 21 31 41 51 61 71 81
45

Sample Output

1
11
21
31
41
45
51
61
71
81

prompt

Defining an array, the array length is defined as 10.

 

 

Long time no knock code This question is a little card for a few minutes. 408 now finished soon, so the beginning of thought is to use direct insertion sort, but later discovered that the subject had already been requested before 9 data ordered, so we changed the idea. (Well, it certainly is food codes) and also for a long time useless break, if used on the outside of breakpoint debugging for a long time only to find orz.

Attach Code:

#include<cstdio>
/*#include<cstring>*/
int main(){
    int i,d;
    int j=9;
    int a[10]={0};
    for(i=0;i<9;i++){
        scanf("%d",&a[i]);
    }
    scanf("%d",&d);
    for(i=0;i<9;i++){
        if(a[i]>=d){
            j=i;
            break;
    }
        }
    for(i=9;i>j;i--){
        a[i]=a[i-1];
    }
    a[j]=d;
    for(i=0;i<10;i++){
        printf("%d\n",a[i]);
    }
}

Published 10 original articles · won praise 1 · views 721

Guess you like

Origin blog.csdn.net/chf2015005328/article/details/86651896