HDOJ-2019 series Order! "Water"

Source: Internet
Author: User

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"

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.