Description
Merge Columns
Two non-descending sequence numbers A and B are given. The value of an element in a series is int, and the number of elements cannot exceed 1,000. Combine two sorted series into a non-ascending series output.
-
Input
-
The input has 3 m + 1 rows. The number of groups of the first behavior test data is M. The following 3 m is the test data of the M group. The first row of the test data contains the numbers A and B, indicating that the next two rows have the numbers A and B respectively, next, Series a B occupies two rows, and the elements in each series are separated by spaces.
-
Output
-
The output contains m rows, which correspond to the input m-group test data. The combined non-ascending sequence is output, and elements are separated by spaces.
Classic Problems
#include<stdio.h>main(){int te,number;int temp1,temp2,temp;int i,j,k;int a[1000],b[1000],c[2000];scanf("%d",&number);for (te=1;te<=number;te++){ k=0;scanf("%d %d",&temp1,&temp2);for(i=0;i<temp1;i++)scanf("%d",&a[i]);for(i=0;i<temp2;i++)scanf("%d",&b[i]);for(i=0;i<temp1;i++){c[k]=a[i];k++;}for(i=0;i<temp2;i++){c[k]=b[i];k++;}for(i=0;i<temp1+temp2;i++) for(j=i+1;j<temp1+temp2;j++) { if(c[i]>c[j]) { temp=c[j]; c[j]=c[i]; c[i]=temp; } }for(i=temp1+temp2-1;i>=1;i--) printf("%d ",c[i]);printf("%d\n",c[0]);}}