Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- MIPT, task #002
- "Set Intersection"
- 12.09.2011
- */
- #include <stdio.h>
- #define MAX_SET_SIZE 1000000
- int main()
- {
- char s[MAX_SET_SIZE + 1] = {0};
- int a;
- while (scanf ("%d", &a) && a != -1) {
- s[a] = 1;
- }
- while (scanf ("%d", &a) && a != -1) {
- if (1 == s[a]) {
- s[a] = 2;
- }
- }
- /*
- Now if s[a] == 1, then a belongs to the first set,
- and if s[a] == 2, then a belongs to the second one.
- */
- char is_intersection = 0;
- for (a = 0; a <= MAX_SET_SIZE; ++a) {
- if (2 == s[a]) {
- is_intersection = 1;
- printf ("%d ", a);
- }
- }
- if (!is_intersection) {
- puts("empty");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment