sum of unique two from given 2 array and do sum of it code example

Example: sum of unique two from given 2 array and do sum of it

#include<iostream>
#include<map>
#include<vector>
using namespace std;

void unique_array_value_sum(int a[],int b[],int s,int e1,int e2)
{
	int sum=0;
	vector<int> v;
	map<int,int> ar1;
	map<int,int> ar2;
	
	for(int x=0;x<e1;x++)
	{
	   ar1[a[x]]++; 
	}
	
	for(auto i:ar1)
	{
	    if(i.second==1)
	    {
	        v.push_back(i.first);
	    }
	}
	
	for(int y=0;y<e2;y++)
	{
	   ar2[b[y]]++; 
	}
	
	for(auto i:ar2)
	{
	    if(i.second==1)
	    {
	        v.push_back(i.first);
	    }
	}
	
	
   map<int,int> un;	
   for(int u=0;u<v.size();u++)
   un[v[u]]++;
   
   for(auto i:un)
   {
       if(i.second==1)
       {
           sum+=i.first;
       }
   }
	cout<<sum;
}



int main()
{
	int n1,n2;
	cout<<"Enter size of 2 arrays:";
	cin>>n1>>n2;
	int a[n1],b[n2];
	
	//scanning 1st array
	for(int p=0;p<n1;p++)
	{
		cin>>a[p];	
	}
	
	//scanning 2nd array
	for(int q=0;q<n2;q++)
	{
		cin>>b[q];	
	}
	
	sort(a,a+n1);
	sort(b,b+n2);
	
	unique_array_value_sum(a,b,0,n1,n2);
	return 0;
}

Tags:

Misc Example