ITGUY09 - Editorial

Problem: Contest Page | CodeChef

DIFFICULTY:

EASY.

PROBLEM:

Chef has three baskets and two of them have multiple balls(Natural numbers written on them). The first basket has N balls, the second basket has M balls and the third basket is empty. Chef starts choosing all the non-unique balls(occurring more than once) and puts into the third basket and throw unique ones. Print numbers on the balls of the third basket in ascending order.

Program:

#include<bits/stdc++.h> 
using namespace std; 
 
int main() 
{ 
	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);
   	int t;
   	cin>>t;
   	while(t--){
   		int n,m,x;
   		cin>>n>>m;
   		map<int,int>mp;
   		for(int i=0;i<n+m;i++){
   			cin>>x;
   			mp[x]++;
   		}
   		for(auto x:mp){
   			if(x.second>1)cout<<x.first<<" ";
   		}
   		cout<<endl;
   	}
}