Advertisement
karlangadas

Banco

Oct 24th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <string.h>
  5. #include "cola.h"
  6. #define MAX 100
  7. void Atencion(TCola *A,TCola *B,int caja);
  8. void llenarArrayRandom(int nA,int nB,char array[MAX]);
  9. int main(){
  10.     srand(time(NULL));
  11.     TCola A;
  12.     TCola B;
  13.     int nA,nB,nC;
  14.     int contA=0;
  15.     int contB=0;
  16.     char array[MAX]={};
  17.     scanf("%d %d %d",&nA,&nB,&nC);
  18.     int j=0;
  19.     llenarArrayRandom(nA,nB,array);
  20.     int i=0;
  21.     while (i<(nA+nB)|| (i==nA+nB && !(Cola_isEmpty(&A) && Cola_isEmpty(&B)))){
  22.         int random=rand() % 2;
  23.         if (random && i<(nA+nB)){
  24.             if (array[i]=='A'){
  25.                 printf("Llegó cliente A%d\n",++contA);
  26.                 Cola_enqueue(&A,contA);
  27.             }
  28.             else{
  29.                 printf("Llegó cliente B%d\n",++contB);
  30.                 Cola_enqueue(&B,contB);
  31.             }
  32.             i++;
  33.         }
  34.         random=rand() % 2;
  35.         if (random && !(Cola_isEmpty(&A) && Cola_isEmpty(&B))){
  36.             int caja=((j++)%nC)+1;
  37.             Atencion(&A,&B,caja);
  38.         }
  39.     }
  40.     return 0;
  41. }
  42.  
  43. void llenarArrayRandom(int nA,int nB,char array[MAX]){
  44.     srand(time(NULL));
  45.     char car[2]={'A','B'};
  46.     int contA=0;
  47.     int contB=0;
  48.  
  49.     for (int i=0;i<nA+nB;){
  50.         int randomIndex = rand() % 2;
  51.         char randomValue = car[randomIndex];
  52.         if (randomValue=='A'){
  53.             if (contA<nA){
  54.                 array[i++]=randomValue;
  55.                 contA++;
  56.             }
  57.         }
  58.         if (randomValue=='B'){
  59.             if (contB<nB){
  60.                 array[i++]=randomValue;
  61.                 contB++;
  62.             }
  63.         }
  64.     }
  65. }
  66. void Atencion(TCola *A,TCola *B,int caja){
  67.     int val;
  68.     if(!Cola_isEmpty(A)){
  69.         val=Cola_dequeue(A);
  70.         printf("Atendiendo cliente A%d en caja %d\n",val,caja);
  71.     }
  72.     else{
  73.         val=Cola_dequeue(B);
  74.         printf("Atendiendo cliente B%d en caja %d\n",val,caja);
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement