Orderly sequence!Time
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 59240 Accepted Submission (s): 25564
Problem description have n (n<=100) integers that have been arranged in order from small to large, and now give an integer x, insert that number into the sequence and keep the new sequence in order.
Input data contains multiple test instances, each set of data consists of two rows, the first row is N and M, the second row is an ordered number of N. N and M also mark the end of the input data for 0, the bank does not do the processing.
Output for each test instance, outputs the number of columns after the new element is inserted.
Sample Input
3 31 2) 40 0
Sample Output
1 2 3 4
Detailed topics:
N (n<=100) integers, arranged in order from small to large
To an integer x, insert the number into the sequence, there are three cases:
When the number of n is 1->n
1.x>a[n]
Direct output of the first n, x final output (note format: spaces and line breaks)
2.X<A[1]
First output m, then output that n number
3.a[1]<x<a[n]
I=1 to N, compares A[i] to X, A[i]>x and A[i] is greater than the first number of x, output m, otherwise output A[I]
Careful observation, the second case can be implemented in the code of the third case
So just write X>a[n] and A[1]<x<a[n] When you hit the code.
#include <stdio.h>int main () {int I,n,m;int a[110];while (scanf ("%d%d", &n,&m), n|m) {int sign=0;for (i=1;i <=n;i++) scanf ("%d", &a[i]), if (M>a[n]) {for (i=1;i<=n;i++) printf ("%d", A[i]);p rintf ("%d\n", m);} else if (m<a[1]) in this case the following code can be implemented//{
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDOJ-2019 series Order! "Water"