Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define N 10
- char* nomi[N] = { "Gio", // 0
- "Zanon", // 1
- "Alessia", // 2
- "Teo", // 3
- "Ronca", // 4
- "Fabbro", // 5
- "Persia", // 6
- "Luca", // 7
- "Lucia", // 8
- "Baldo", // 9
- };
- int giftTo[N] = { 0 };
- int occup[N] = { 0 };
- int isValid()
- {
- for (int i = 0; i < N; i++)
- {
- if (giftTo[i] == i) return 0; // Everyone to self
- }
- if (giftTo[0] == 3) return 0; // Gio to Teo
- if (giftTo[1] == 4) return 0; // Zanon to Ronca
- if (giftTo[2] == 8) return 0; // Alessia to Lucia
- if (giftTo[3] == 9) return 0; // Teo to Baldo
- if (giftTo[4] == 2) return 0; // Ronca to Alessia
- if (giftTo[7] == 1) return 0; // Luca to Zanon
- if (giftTo[8] == 7) return 0; // Lucia to Luca
- if (giftTo[9] == 0) return 0; // Baldo to Gio
- if (giftTo[2] == 3 || giftTo[3] == 2) return 0; // Alessia to Teo or Teo to Alessia
- return 1;
- }
- int main()
- {
- srand(time(NULL));
- do
- {
- for (int i = 0; i < N; i++)
- {
- occup[i] = 0;
- }
- for (int i = 0; i < N; i++)
- {
- do
- {
- giftTo[i] = rand() % N;
- } while (occup[giftTo[i]] == 1);
- occup[giftTo[i]] = 1;
- }
- } while (!isValid());
- for (int i = 0; i < N; i++)
- {
- printf("%10s deve fare un regalo a %s\n", nomi[i], nomi[giftTo[i]]);
- }
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement