Q).
=> Solution :
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> removeDupMerge(int a1[],int a2[],int m,int n){
vector<int> mVec;
for(int i=0;i<m-1;i++){
if(a1[i]!=a1[i+1])
mVec.push_back(a1[i]);
}
mVec.push_back(a1[m-1]);
for(int i=0;i<n-1;i++){
if(a2[i]!=a2[i+1])
mVec.push_back(a2[i]);
}
mVec.push_back(a2[n-1]);
sort(mVec.begin(),mVec.end());
return mVec;
}
int main(){
int m,n;
vector<int> myVec;
cin>>m;
int a1[m];
for(int i=0;i<m;i++)
cin>>a1[i];
cin>>n;
int a2[n];
for(int i=0;i<n;i++)
cin>>a2[i];
sort(a1,a1+m);
sort(a2,a2+n);
cout<<"\n\n*******| OUTPUT |*******\n\n";
myVec=removeDupMerge(a1,a2,m,n);
//find median
int median,sVec=myVec.size();
if(sVec%2==0){
median=(sVec-1)/2 + sVec/2;
}else{
median=(sVec-1)/2;
}
cout<<myVec[median]<<endl;
}
Comments
Post a Comment