#include <iostream>
using namespace std;
void aUnionB(int A[], int B[], int a, int b)
{
int n = a + b;
int aUb[n]{0}; // n is max num of elements aUb can have
// filling elements of a in aUb
for (int i = 0; i < a; i++)
{
aUb[i] = A[i];
}
int z = sizeof(aUb) / sizeof(aUb[0]);
int temp = z;
// compare element from set B with aUb and if not fount add it in aUb
for (int i = 0; i < z; i++)
{
for (int j = 0; j < b; j++)
{
if (aUb[i] == B[j])
{
continue;
}
else
{
aUb[temp] = B[j];
temp++;
}
}
}
//print a union b
for (int i : aUb)
{
cout << i << " ";
}
}
int main()
{
int TestCases = 1, NoOfElementsInA, NoOfElementsInB, element;
while (TestCases--) //testing for just one test case
{
cin >> NoOfElementsInA >> NoOfElementsInB;
int A[NoOfElementsInA], B[NoOfElementsInB];
//assigning elements in array A
for (int i = 0; i < NoOfElementsInA; i++)
{
cin >> element;
A[i] = element;
}
//assigning elements in array B
for (int i = 0; i < NoOfElementsInB; i++)
{
cin >> element;
B[i] = element;
}
aUnionB(A, B, NoOfElementsInA, NoOfElementsInB);
}
return 0;
}
I am trying for past 1 hour what's the problem but unable to find why the program is not running despite not having any error or warning after execution , I'm not able to pass inputs.
This the numerical question:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consist of three lines. The first line of each test case contains two space separated integers N and M, where N is the size of array A and M is the size of array B. The second line of each test case contains N space separated integers denoting elements of array A. The third line of each test case contains M space separated integers denoting elements of array B.
Aucun commentaire:
Enregistrer un commentaire