Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <string.h>
- #include "cola.h"
- #define MAX 100
- void Atencion(TCola *A,TCola *B,int caja);
- void llenarArrayRandom(int nA,int nB,char array[MAX]);
- int main(){
- srand(time(NULL));
- TCola A;
- TCola B;
- int nA,nB,nC;
- int contA=0;
- int contB=0;
- char array[MAX]={};
- scanf("%d %d %d",&nA,&nB,&nC);
- int j=0;
- llenarArrayRandom(nA,nB,array);
- int i=0;
- while (i<(nA+nB)|| (i==nA+nB && !(Cola_isEmpty(&A) && Cola_isEmpty(&B)))){
- int random=rand() % 2;
- if (random && i<(nA+nB)){
- if (array[i]=='A'){
- printf("Llegó cliente A%d\n",++contA);
- Cola_enqueue(&A,contA);
- }
- else{
- printf("Llegó cliente B%d\n",++contB);
- Cola_enqueue(&B,contB);
- }
- i++;
- }
- random=rand() % 2;
- if (random && !(Cola_isEmpty(&A) && Cola_isEmpty(&B))){
- int caja=((j++)%nC)+1;
- Atencion(&A,&B,caja);
- }
- }
- return 0;
- }
- void llenarArrayRandom(int nA,int nB,char array[MAX]){
- srand(time(NULL));
- char car[2]={'A','B'};
- int contA=0;
- int contB=0;
- for (int i=0;i<nA+nB;){
- int randomIndex = rand() % 2;
- char randomValue = car[randomIndex];
- if (randomValue=='A'){
- if (contA<nA){
- array[i++]=randomValue;
- contA++;
- }
- }
- if (randomValue=='B'){
- if (contB<nB){
- array[i++]=randomValue;
- contB++;
- }
- }
- }
- }
- void Atencion(TCola *A,TCola *B,int caja){
- int val;
- if(!Cola_isEmpty(A)){
- val=Cola_dequeue(A);
- printf("Atendiendo cliente A%d en caja %d\n",val,caja);
- }
- else{
- val=Cola_dequeue(B);
- printf("Atendiendo cliente B%d en caja %d\n",val,caja);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement