Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n,m;
- cin>>m>>n;
- if(m<n||m<0||n<0||m>=100)
- {
- cout<<"Invalid input"<<endl;//checking if m satisfies the conditions
- return 0;
- }
- int i,a_ar[m],b_ar[n],cnt=0;
- unordered_map<int,int>mp;
- for(i=0; i<m; i++)
- {
- cin>>a_ar[i];//taking input of a array
- mp[a_ar[i]]++;//incrementing the frequency (value) of the element (key)
- }
- for(i=0; i<n; i++)
- cin>>b_ar[i];
- for(i=0; i<n; i++)
- {
- if(mp.find(b_ar[i])==mp.end())//if an element of b array is not found in the map then break
- break;
- else
- cnt++;//else if found then increment the count of found elements
- }
- if(cnt==n)
- cout<<"b_array is a subset of a_array"<<endl;
- else
- cout<<"b_array is not a subset of a_array"<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment