Adrita

ds lab 8 task 1

Jul 28th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,m;
  6. cin>>m>>n;
  7. if(m<n||m<0||n<0||m>=100)
  8. {
  9. cout<<"Invalid input"<<endl;//checking if m satisfies the conditions
  10. return 0;
  11. }
  12. int i,a_ar[m],b_ar[n],cnt=0;
  13. unordered_map<int,int>mp;
  14. for(i=0; i<m; i++)
  15. {
  16. cin>>a_ar[i];//taking input of a array
  17. mp[a_ar[i]]++;//incrementing the frequency (value) of the element (key)
  18. }
  19. for(i=0; i<n; i++)
  20. cin>>b_ar[i];
  21. for(i=0; i<n; i++)
  22. {
  23. if(mp.find(b_ar[i])==mp.end())//if an element of b array is not found in the map then break
  24. break;
  25. else
  26. cnt++;//else if found then increment the count of found elements
  27. }
  28. if(cnt==n)
  29. cout<<"b_array is a subset of a_array"<<endl;
  30. else
  31. cout<<"b_array is not a subset of a_array"<<endl;
  32.  
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment