fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int arr1[]={2,4,7,1,5};
  6. int arr2[]={5,4,2};
  7. int m=sizeof(arr1)/sizeof(arr1[0]);
  8. int n=sizeof(arr2)/sizeof(arr2[0]);
  9. unordered_set<int> s;
  10. for(int i=0;i<m;i++)
  11. s.insert(arr1[i]);
  12. for(int i=0;i<n;i++){
  13. if(s.count(arr2[i])==0)
  14. {
  15. cout<<"arr2 is not a subset of arr1";
  16. break;
  17. }
  18. }
  19. cout<<"arr2 is a subset of arr1";
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
arr2 is a subset of arr1