Guest User

Untitled

a guest
Jan 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1.  
  2. /*
  3. MIPT, task #002
  4. "Set Intersection"
  5. 12.09.2011
  6. */
  7.  
  8. #include <stdio.h>
  9.  
  10. #define MAX_SET_SIZE 1000000
  11.  
  12. int main()
  13. {
  14. char s[MAX_SET_SIZE + 1] = {0};
  15. int a;
  16.  
  17. while (scanf ("%d", &a) && a != -1) {
  18. s[a] = 1;
  19. }
  20.  
  21. while (scanf ("%d", &a) && a != -1) {
  22. if (1 == s[a]) {
  23. s[a] = 2;
  24. }
  25. }
  26.  
  27. /*
  28. Now if s[a] == 1, then a belongs to the first set,
  29. and if s[a] == 2, then a belongs to the second one.
  30. */
  31.  
  32. char is_intersection = 0;
  33. for (a = 0; a <= MAX_SET_SIZE; ++a) {
  34. if (2 == s[a]) {
  35. is_intersection = 1;
  36. printf ("%d ", a);
  37. }
  38. }
  39.  
  40. if (!is_intersection) {
  41. puts("empty");
  42. }
  43.  
  44. return 0;
  45. }
Add Comment
Please, Sign In to add comment