Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #define MAXFILA 30
- struct TpFila
- {
- int Inicio, Fim, Cont;
- int Fila[MAXFILA];
- };
- void Inicializar(TpFila &F)
- {
- F.Cont = 0;
- F.Inicio = 0;
- F.Fim = -1;
- }
- void Inserir(TpFila &F, int C)
- {
- if(F.Fim == MAXFILA - 1)
- F.Fim = -1;
- F.Fila[++F.Fim] = C;
- F.Cont++;
- }
- int Retirar(TpFila &F, int n)
- {
- int L = F.Fila[F.Inicio++];
- if(F.Inicio == n)
- F.Inicio = 0;
- F.Cont--;
- return L;
- }
- char Cheia(int Qtde)
- {
- return Qtde == MAXFILA;
- }
- char Vazia(int Qtde)
- {
- return Qtde == 0;
- }
- char ElemInicio(TpFila F)
- {
- return F.Fila[F.Inicio];
- }
- char ElemFim(TpFila F)
- {
- return F.Fila[F.Fim];
- }
- void Exibe(TpFila F)
- {
- while(!Vazia(F.Cont))
- printf("%d\n", Retirar(F, MAXFILA));
- }
- int main(void)
- {
- TpFila F, Aux;
- int n, k, m, i, posH, posAH, c;
- scanf("%d %d %d", &n, &k, &m);
- while(n > 0 && k > 0 && m > 0)
- {
- Inicializar(F);
- Inicializar(Aux);
- for(i = 1; i <= n; i++)
- Inserir(F, i);
- posH = 0; posAH = n;
- while(!Vazia(F.Cont))
- {
- posH += k;
- if(posH > n)
- posH = posH % F.Cont;
- if(posH == 0)
- posH = n;
- posAH -= m;
- if(posAH < 0)
- posAH = posAH % F.Cont;
- while(F.Inicio != posH - 1)
- Inserir(Aux, Retirar(F, n));
- i = Retirar(F, n);
- while(!Vazia(F.Cont))
- Inserir(Aux, Retirar(F, n));
- /*if(c > 0)
- printf(",");
- */
- if(i < 10)
- printf(" ");
- else if(i < 100)
- printf(" ");
- if(posAH != posH)
- {
- posAH--;
- if(posAH < 0)
- posAH = n - 1;
- while(!Vazia(Aux.Cont) && Aux.Inicio != posAH)
- Inserir(F, Retirar(Aux, n));
- i = Retirar(Aux, n);
- if(i < 10)
- printf(" ");
- else if(i < 100)
- printf(" ");
- //printf("%d", i);
- while(!Vazia(Aux.Cont))
- Inserir(F, Retirar(Aux, n));
- }
- while(!Vazia(Aux.Cont))
- Inserir(F, Retirar(Aux, n));
- printf("\n");
- Exibe(F);
- c++;
- }
- printf("\n");
- scanf("%d %d %d", &n, &k, &m);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement