Advertisement
Guest User

Untitled

a guest
Oct 19th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int A[] = {1,2,3,4,5};
  4. int B[] = {1,3,4};
  5.  
  6.  
  7. int ReadArr(int Arr[], int s){
  8. int i;
  9. for(i = 0; i < s; i++){
  10. scanf("%d", &Arr[i]);
  11. }
  12. }
  13.  
  14.  
  15. int Intersect(int sA, int sB){
  16.  
  17. int I = 0;
  18. int ia, ib;
  19.  
  20. for(ia = 0; ia < sA; ia++){
  21. for(ib = 0; ib < sB; ib++){
  22. if(A[ia] == B[ib]){
  23. I += 1;
  24. break;
  25. }
  26. }
  27. }
  28.  
  29. return I;
  30. }
  31.  
  32.  
  33. int Union(int sA, int sB){
  34.  
  35. int U = sA + sB;
  36. int ia, ib;
  37.  
  38. for(ia = 0; ia < sA; ia++){
  39. for(ib = 0; ib < sB; ib++){
  40. if(A[ia] == B[ib]){
  41. U -= 1;
  42. break;
  43. }
  44. }
  45. }
  46.  
  47. return U;
  48. }
  49.  
  50.  
  51. int main(){
  52. int sA, sB;
  53. int I, U;
  54.  
  55. scanf("%d", &sA);
  56. ReadArr(A, sA);
  57.  
  58. scanf("%d", &sB);
  59. ReadArr(B, sB);
  60.  
  61. I = Intersect(sA, sB);
  62. U = Union(sA, sB);
  63.  
  64. printf("%d\n", I);
  65. printf("%d\n", U);
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement