Here in the below code i have 4 vectors a
,b
,v1
,v2
.
After calculating set difference of a and b, b and a I have stored the reuslts of them in v1 and v2 vectors respectively.
- vector 'a' has the elements {'a','b','c'} and
- vector 'b' has the elements {'a','b'}.
- Now v1 contains 'c' with its size 1 but v2 contains none and with size 1. How is this possible? Note that vectors a and b contains the elements of a set!!!
Here is my code:
#include <bits/stdc++.h>
#define REP(i,x,y) for(auto i=x;i!=y;i++)
using namespace std;
int t;
string s1,s2;
bool flag;
int main()
{
cin>>t;
while(t--)
{
flag=false;
set<char> a,b; multiset<char> A,B;
cin>>s1>>s2;
REP(i,0,s1.length())
{
A.insert(s1[i]);
a.insert(s1[i]);
B.insert(s2[i]);
b.insert(s2[i]);
}
vector<char> v1,v2;
set_difference(a.begin(),a.end(),b.begin(),b.end(),inserter(v1,v1.begin()));
set_difference(b.begin(),b.end(),a.begin(),a.end(),inserter(v2,v2.begin()));
cout<<v1.size()<<" "<<v2.size()<<"\n";
REP(i,v1.begin(),v1.end())
cout<<*i<<" ";
cout<<"\n";
REP(i,v2.begin(),v2.end())
cout<<*i<<" ";
cout<<"\n";
}
return 0;
}
Input: 3 abaac ab aba cde ab cd
Output:
1 1
c
2 3
a b
c d e
2 2
a b
c d