pegasus975

kelver

Jun 17th, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <conio.h>
  4. #include <dos.h>
  5. #include <stdlib.h>
  6. #include <windows.h>
  7. #include <time.h>
  8. #include <ctype.h>
  9. #include <locale.h>
  10. #include <math.h>
  11.  
  12. void cores(int ForgC, int BackC){   // para chamar
  13.      WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);;
  14.      SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
  15.      return;
  16. }
  17.  
  18. void textcolor(int newcolor){
  19.    CONSOLE_SCREEN_BUFFER_INFO csbi;
  20.    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
  21.    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
  22.      (csbi.wAttributes & 0xf0) | newcolor);
  23. }
  24. void gotoxy(int x, int y) {
  25.   COORD c;
  26.   c.X = x - 1;
  27.   c.Y = y - 1;
  28.   SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
  29. }
  30. void imp_autor(){
  31.   setlocale(LC_ALL, "Portuguese");
  32.   gotoxy(27,12);
  33.   textcolor(10);
  34.   printf("Fernando Henrique Arnhold");
  35.   Sleep(250);
  36.   system("cls");
  37.   textcolor(15);
  38. }
  39. //GLOBAL
  40. struct pessoas{
  41. char nome[20];
  42. int proximo;
  43. };
  44. struct pessoas pes[10];
  45. int anterior;
  46. int primeiro;
  47. //FUNCTIONS
  48.  
  49. void preenche(){
  50.     strcpy(pes[0].nome, "BILL GATES");
  51.     strcpy(pes[1].nome, "PAUL ALLEN");
  52.     strcpy(pes[2].nome, "STEVE BALLMER");
  53.     strcpy(pes[3].nome, "CLIVE SINCLAIR");
  54.     strcpy(pes[4].nome, "PETER CHEN");
  55.     strcpy(pes[5].nome, "STEVE WOZNIAK");
  56.     strcpy(pes[6].nome, "JEAN PAUL JACOB");
  57.     strcpy(pes[7].nome, "STEVE JOBS");
  58.     strcpy(pes[8].nome, "ADA LOVELACE");
  59.     strcpy(pes[9].nome, "BLAISE PASCAL");
  60.    
  61.     int i;
  62.     for(i = 0; i < 10; i++){
  63.         pes[i].proximo = -2;  
  64.     }
  65. }
  66. void firstPeople(){
  67. primeiro = anterior = rand()%10;   
  68. }
  69. // -------------- AQUI COMEÇA NOSSO PROGRAMA PROPRIAMENTE DITO -----------------
  70. main()
  71. {
  72. int posAtual, cont=0;
  73. int proximo;
  74.  
  75.    imp_autor();  
  76.    srand(time(NULL));
  77.    preenche();
  78.    firstPeople();
  79.    
  80.     while(cont < 9 ){
  81. posAtual = rand()%10;
  82. while(pes[posAtual].proximo == -2 && posAtual != anterior){
  83. pes[anterior].proximo = posAtual;
  84. anterior = posAtual;
  85.                 cont++;
  86. }  
  87. }  
  88.    int i=1;
  89.    printf("\n    ***FILA SORTEADA***\n");
  90.    printf("\n%4dº %4s", i, pes[primeiro].nome);
  91.    proximo = pes[primeiro].proximo;
  92. for(i=1;i<10;i++){
  93. printf("\n%4dº %4s  %4d",i+1, pes[proximo].nome, pes[proximo].proximo);
  94. proximo = pes[proximo].proximo;    
  95. }
  96.    getch(); // força uma parada do programa no final da seua execução.
  97. }
Advertisement
Add Comment
Please, Sign In to add comment