Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4.  
  5. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  6.  
  7. int main(int argc, char *argv[]) {
  8. int n,k,i=0,j=0, licznik=0, pozycja_nastepny=0;
  9. bool sprawdzenie=false;
  10. printf("Podaj liczbe rycerzy: ");
  11. scanf("%i",&n);
  12. printf("Podaj krok eliminacji: ");
  13. scanf("%i",&k);
  14. int rycerzy[n];
  15. for(i=0;i<n;i++)
  16. rycerzy[i]=1;
  17.  
  18. for(i=0;i<n;i++)
  19. printf("%i",rycerzy[i]);
  20.  
  21. printf("\n--------------------\n");
  22.  
  23. for(licznik=0;licznik<n;licznik++){
  24. j=0;sprawdzenie=false;
  25. i=pozycja_nastepny;
  26. while(sprawdzenie!=true){
  27. if(rycerzy[i]!=0)
  28. j=j+1;
  29. if(j==k) {
  30. rycerzy[i]=0;
  31. sprawdzenie=true;
  32. pozycja_nastepny=i;
  33. }
  34. if(i>=n) i=0; else i++;
  35. }
  36. for(i=0;i<n;i++)
  37. printf("%i",rycerzy[i]);
  38. printf("\n");
  39. }
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement