fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool checkSubset(vector<int>a , vector<int>b){
  5. unordered_set<int>st;
  6. for(int x:a){
  7. st.insert(x);
  8. }
  9. for(int x:b){
  10. if(st.find(x)==st.end()){
  11. return false;
  12. }
  13. }
  14. return true;
  15. }
  16.  
  17. int main() {
  18. int n;
  19. cin>>n;
  20. vector<int>arr(n);
  21. for(int i=0;i<n;i++){
  22. cin>>arr[i];
  23. }
  24.  
  25. int m;
  26. cin>>m;
  27. vector<int>brr(m);
  28. for(int i=0;i<m;i++){
  29. cin>>brr[i];
  30. }
  31. if(checkSubset(arr,brr)){
  32. cout<<"Array2 is subset of Array1."<<endl;
  33. return 0;
  34. }
  35. else{
  36. cout<<"Not a subset.";
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5288KB
stdin
5
2 4 7 1 5
3
2 1 4
stdout
Array2 is subset of Array1.