Advertisement
Coriic

Untitled

Jan 16th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. struct sedzia{
  7. char *nazwisko;
  8. int index;
  9. };
  10.  
  11. struct wezel{
  12. struct sedzia *wsk;
  13. struct wezel *next;
  14. };
  15.  
  16. void dodaj (struct wezel **poczatek, int *liczba){
  17. struct wezel *tmp;
  18. char bufor[20];
  19. int dlugosc;
  20. tmp=(struct wezel*)malloc(sizeof(struct wezel));
  21. tmp->wsk=(struct sedzia*)malloc(sizeof(struct sedzia));
  22. getchar();
  23. printf("Podaj nazwisko sedziego: ");
  24. fgets(bufor, 20, stdin);
  25. dlugosc=strlen(bufor);
  26. tmp->wsk->nazwisko=(char *)malloc(sizeof(char)*(dlugosc+1));
  27. strcpy(tmp->wsk->nazwisko, bufor);
  28. printf("Podaj identyfikator sedziego: ");
  29. scanf("%d", &(tmp->wsk->index));
  30. tmp->next=*poczatek;
  31. *poczatek=tmp;
  32. *liczba=*liczba+1;
  33. }
  34.  
  35. void wyswietl (struct wezel *poczatek){
  36. struct wezel *tmp;
  37. tmp=poczatek;
  38. while (tmp != NULL){
  39. printf("Nazwisko: %s\n", tmp->wsk->nazwisko);
  40. printf("Identyfikator: %d\n", tmp->wsk->index);
  41. tmp=tmp->next;
  42. }
  43. }
  44.  
  45. void losuj (struct wezel *poczatek, int liczba){
  46. int zarodek, i, j,a,m,losowany,b, nd;
  47. int **druzyny;
  48. struct wezel *tmp;
  49. m=0;
  50. zarodek=time(NULL);
  51. printf("Podaj liczbe druzyn: ");
  52. scanf("%d", &nd);
  53. druzyny=(int **)malloc(nd*sizeof(int *));
  54. for (i=nd-1, j=0; i>0 && j<nd; i--, j++){
  55. *(druzyny+j)=(int *)malloc(i*sizeof(int));
  56. srand(zarodek);
  57. a=rand()%liczba;
  58. tmp=poczatek;
  59. while((m <= a) && (tmp!=NULL)){
  60. losowany=tmp->wsk->index;
  61. m++;
  62. tmp=tmp->next;
  63. }
  64. for (b=0; b<i; b++){
  65. *(*(druzyny+j)+b)=losowany;
  66. printf("Druzyna %d i druzyna %d, sedzia: %d\n", j+1, j+b+2, losowany);
  67.  
  68. }
  69. }
  70. }
  71.  
  72. int main(void){
  73. struct wezel *poczatek;
  74. int wybor, liczba;
  75. poczatek=NULL;
  76. liczba=0;
  77. while (wybor != 0){
  78. printf("1) Dodaj sedziego\n");
  79. printf("2) Wyswietl liste\n");
  80. printf("3) Losuj\n");
  81. printf("0) Wyjdz\n");
  82. scanf("%d", &wybor);
  83. if (wybor==1){
  84. dodaj(&poczatek, &liczba);
  85. }
  86. if (wybor==2){
  87. wyswietl(poczatek);
  88. }
  89. if (wybor==0){
  90. break;
  91. }
  92. if (wybor==3){
  93. losuj(poczatek, liczba);
  94. }
  95. wybor=-1;
  96. }
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement