Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.5 kB
1
Indexable
Never
int main() {

    Queue fast,normal;
    Element element;
    char comando;
    char basura;
    int cantidadfast = 0,cantidadnormal = 0;

    fast = QUEUE_create();
    normal = QUEUE_create();

    /*
        F -> Fast
        N -> Normal
        A -> Enter attraction
        Q -> Quit
    */

    do {

        scanf("%c",&comando); //Solo roba hasta el ' ' o el '\n'
        scanf("%c",&basura); //Roba el espacio o el salto de linea

        switch(comando) {
            case 'F':
                scanf("%d",&element.size);
                scanf("%c",&basura);
                scanf("%s",element.name);
                scanf("%c",&basura);

                QUEUE_add(&fast,element);
                if(!QUEUE_isFull(fast)) {
                    printf("%s (%d) has been added to the Fast queue.\n",element.name,element.size);
                } else {
                    printf("The Fast queue is full.\n");
                }
                break;

            case 'N':
                scanf("%d",&element.size);
                scanf("%c",&basura);
                scanf("%s",element.name);
                scanf("%c",&basura);

                QUEUE_add(&fast,element);
                if(!QUEUE_isFull(normal)) {
                    printf("%s (%d) has been added to the Normal queue.\n",element.name,element.size);
                } else {
                    printf("The Normal queue is full.\n");
                }
                break;

            case 'A':

                if(QUEUE_isEmpty(fast) && QUEUE_isEmpty(normal)) {
                    printf("No group is available yet.\n");
                } else {
                    if(!QUEUE_isEmpty(fast)) {
                        element = QUEUE_getFirst(&fast);
                        printf("%s (%d) has entered the attraction.\n",element.name,element.size);
                        QUEUE_remove(&fast);
                    } else {
                        if(!QUEUE_isEmpty(normal)) {
                            element = QUEUE_getFirst(&normal);
                            printf("%s (%d) has entered the attraction.\n",element.name,element.size);
                            QUEUE_remove(&normal);
                        }
                    }

                }
                break;

            case 'Q':
                QUEUE_destroy(&fast);
                QUEUE_destroy(&normal);
                printf("See you soon!\n");
                break;                
        }

    }while(comando != 'Q');

    return 0;
}