SORT13
QUESTION DESCRIPTION
You have to merge the two sorted arrays into one sorted array (in non-increasing order)
Input:
First line contains an integer T, denoting the number of test cases.
First line of each test case contains two space separated integers X and Y, denoting the size of the two sorted arrays.
Second line of each test case contains X space separated integers, denoting the first sorted array P.
Third line of each test case contains Y space separated integers, denoting the second array Q.
Output:
For each test case, print (X + Y) space separated integer representing the merged array.
You have to merge the two sorted arrays into one sorted array (in non-increasing order)
Input:
First line contains an integer T, denoting the number of test cases.
First line of each test case contains two space separated integers X and Y, denoting the size of the two sorted arrays.
Second line of each test case contains X space separated integers, denoting the first sorted array P.
Third line of each test case contains Y space separated integers, denoting the second array Q.
Output:
For each test case, print (X + Y) space separated integer representing the merged array.
TEST CASE 2
INPUT
INPUT
2
5 6
8 5 3 1 0
15 12 10 7 4 2
4 2
8 6 3 0
7 1
OUTPUT15 12 10 8 7 5 4 3 2 1 0
8 7 6 3 1 0
#include <stdio.h>
int main() {
int t,N1,N2,arr[101],i,j,temp;
scanf("%d",&t);
while(t-->0)
{
scanf("%d %d", &N1, &N2);
for (i=0; i<N1; i++)
scanf("%d", &arr[i]);
for (i=N1; i<N2+N1; i++)
scanf("%d", &arr[i]);
for (i=0 ; i<(N1+N2)-1; i++)
{
for (j=0 ; j<(N1+N2)-i-1; j++)
{
if (arr[j] < arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
for(i=0;i<(N1+N2);i++)
printf("%d ",arr[i]);
printf("\n");
}
return 0;
}
Comments
Post a Comment