fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <memory.h>
  4.  
  5. int in(int val, const int* begin, const int* end){
  6. while(begin != end)
  7. if(*(begin++) == val) return 1;
  8. return 0;
  9. }
  10.  
  11. int isSubset(const int* A, size_t Na, const int* B, size_t Nb){
  12. while(Na)
  13. if(in(A[--Na], B, B + Nb)) return 1;
  14. return 0;
  15. }
  16.  
  17. int main(void) {
  18. size_t Na, Nb;
  19. scanf("%lu %lu", &Na, &Nb);
  20.  
  21. int* A = (int*)calloc(Na, sizeof(int));
  22. int* B = (int*)calloc(Nb, sizeof(int));
  23.  
  24. for(size_t i = 0; i < Na; i++)
  25. scanf("%d", A + i);
  26.  
  27. for(size_t i = 0; i < Nb; i++)
  28. scanf("%d", B + i);
  29.  
  30. printf("%s\n", isSubset(A, Na, B, Nb) ? "A in B" : "A not in B");
  31.  
  32. free(A);
  33. free(B);
  34.  
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 9424KB
stdin
3 4
1 2 3
4 1 3 2
stdout
A in B