Merging of two ordered series

Source: Internet
Author: User

Title Description

Known quantity Group A has m-ascending elements in array B with n descending elements, programmed to deposit all elements A and B into array C in descending order.

Input

The input has two lines, the first line is a positive integer m, then a M integer, the second line is first a positive integer n, then n integers, m, n is less than or equal to 1000000.

Output

Outputs the merged m+n integers, separated by a space between the data. The output takes up one row.

Sample input4 1 3 5 7 3 6 4 2Sample output7 6 5 4 3 2 1Tips

Try to sort out the children to be careful ~~~~~~

1# include <stdio.h>2# define N10000103 intA[n], B[n], c[2*N];4 intMain ()5 {6     intI, J, K, M, n, flag =0;7scanf"%d", &m);8      for(i = m-1; I >=0; i--)9scanf"%d", &a[i]);Ten   Onescanf"%d", &n); A      for(j =0; J < N; J + +) -scanf"%d", &b[j]); -i =0; thej =0; -K =0; -      while(I < m && J <N) -     { +         if(A[i] >B[j]) -c[k++] = a[i++]; +         Else Ac[k++] = b[j++]; at     } -      while(I <m) -c[k++] = a[i++]; -      while(J <N) -c[k++] = b[j++]; -      for(i =0; I < K; i++) in     { -         if(Flag = =0) toprintf"%d", C[i]); +         Else -printf"%d", C[i]); theFlag =1; *     } $printf"\ n");Panax Notoginseng     return 0; -}

Merging of two ordered series

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.