#include <stdio.h>
#include <stdlib.h>
#include <time.h>

// Função para verificar se um número já existe num array
int existe(int array[], int tamanho, int numero) {
    for (int i = 0; i < tamanho; i++) {
        if (array[i] == numero) {
            return 1; // Verdadeiro, o número já existe
        }
    }
    return 0; // Falso, o número não existe
}

// Função para ordenar um array em ordem crescente
void ordenar(int array[], int tamanho) {
    for (int i = 0; i < tamanho - 1; i++) {
        for (int j = 0; j < tamanho - i - 1; j++) {
            if (array[j] > array[j + 1]) {
                int temp = array[j];
                array[j] = array[j + 1];
                array[j + 1] = temp;
            }
        }
    }
}

int main() {
    int numeros[5]; // Array para os 5 números principais
    int estrelas[2]; // Array para as 2 estrelas
    int i;

    // Inicializar a semente para números aleatórios com base no tempo
    srand(time(NULL));

    // Gerar 5 números principais únicos (1 a 50)
    for (i = 0; i < 5; i++) {
        int novo_numero;
        do {
            novo_numero = (rand() % 50) + 1; // Gera número entre 1 e 50
        } while (existe(numeros, i, novo_numero)); // Repete se já existir
        numeros[i] = novo_numero;
    }

    // Ordenar os números principais
    ordenar(numeros, 5);

    // Gerar 2 estrelas únicas (1 a 12)
    for (i = 0; i < 2; i++) {
        int nova_estrela;
        do {
            nova_estrela = (rand() % 12) + 1; // Gera número entre 1 e 12
        } while (existe(estrelas, i, nova_estrela)); // Repete se já existir
        estrelas[i] = nova_estrela;
    }

    // Ordenar as estrelas
    ordenar(estrelas, 2);

    // Mostrar a chave gerada
    printf("Chave do Euromilhoes:\n");
    printf("Numeros: ");
    for (i = 0; i < 5; i++) {
        printf("%d ", numeros[i]);
    }
    printf("\nEstrelas: %d %d\n", estrelas[0], estrelas[1]);

    return 0;
}