Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 29.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. typedef struct player
  6. {
  7.     char name[100];
  8.     char surname[100];
  9.     char city[100];
  10.     int yearOfBirth;
  11.     int id;
  12.     struct player *next;
  13. }PLAYER;
  14. typedef struct competition
  15. {
  16.     int trying;
  17.     double startTime;
  18.     char name[100];
  19.     int id;
  20.     struct competition *next;
  21. }COMPETITION;
  22. typedef struct finale
  23. {
  24.     struct player *player;
  25.     struct competition *competition;
  26.     double time[5];
  27.     struct finale *next
  28. }FINALE;
  29. PLAYER *FindPlayer(PLAYER *pierwszy, int id)
  30. {
  31.     PLAYER *current=pierwszy;
  32.     while(current!=NULL)
  33.     {
  34.         if(current->id==id)
  35.         {
  36.             return current;
  37.         }
  38.         current=current->next;
  39.     }
  40. }
  41. COMPETITION *FindCompetition(COMPETITION *pierwszy, int id)
  42. {
  43.     COMPETITION *current=pierwszy;
  44.     while(current!=NULL)
  45.     {
  46.         if(current->id==id)
  47.         {
  48.             return current;
  49.         }
  50.         current=current->next;
  51.     }
  52. }
  53. PLAYER *CreatePlayer(char name[100], char surname[100], char city[100], int yearOfBirth, int id)
  54. {
  55.     PLAYER *item=(PLAYER*)malloc(sizeof(PLAYER));
  56.     item->yearOfBirth=yearOfBirth;
  57.     item->id=id;
  58.     strcpy(item->name,name);
  59.     strcpy(item->surname,surname);
  60.     strcpy(item->city,city);
  61.     item->next=NULL;
  62.     return item;
  63. }
  64. void AddPlayer(PLAYER ** pierwszy , char name[], char surname[], char city[], int yearOfBirth, int id)
  65. {
  66.     PLAYER *item = CreatePlayer(name, surname, city, yearOfBirth, id);
  67.     PLAYER *pom = *pierwszy;
  68.     if(*pierwszy == NULL)
  69.     {
  70.         *pierwszy = item;
  71.     }
  72.     else
  73.     {
  74.         while(pom->next != NULL)
  75.         {
  76.             pom=pom->next;
  77.         }
  78.         pom->next = item;
  79.     }
  80. }
  81. void printAllPlayers(PLAYER *pierwszy)
  82. {
  83.     if(pierwszy==NULL)
  84.     {
  85.         printf("\nBrak informacji na temat zawodnikow.");
  86.     }
  87.     else
  88.     {
  89.         PLAYER *current=pierwszy;
  90.         int i=0;
  91.         while(current!=NULL)
  92.         {
  93.             i++;
  94.             printf("\nid=%d imie=%s nazwisko=%s miasto=%s rok urodzenia=%d",current->id, current->name, current->surname, current->city, current->yearOfBirth);
  95.             current=current->next;
  96.         }
  97.     }
  98. }
  99. COMPETITION *CreateCompetition(char name[100], int trying, double startTime, int id)
  100. {
  101.     COMPETITION *item=(COMPETITION*)malloc(sizeof(COMPETITION));
  102.     item->trying=trying;;
  103.     strcpy(item->name,name);
  104.     item->startTime=startTime;
  105.     item->id=id;
  106.     item->next=NULL;
  107.     return item;
  108. }
  109. void AddCompetition(COMPETITION ** first, char name[100], int trying, double startTime, int id)
  110. {
  111.     COMPETITION *item = CreateCompetition(name, trying, startTime, id);
  112.     COMPETITION *pom = *first;
  113.     if(*first == NULL)
  114.     {
  115.         *first = item;
  116.     }
  117.     else
  118.     {
  119.         while(pom->next != NULL)
  120.         {
  121.             pom=pom->next;
  122.         }
  123.         pom->next = item;
  124.     }
  125. }
  126. void printAllCompetition(COMPETITION *first)
  127. {
  128.     if(first==NULL)
  129.     {
  130.         printf("\nBrak informacji na temat konkurencji.");
  131.     }
  132.     else
  133.     {
  134.         COMPETITION *current=first;
  135.         int i=0;
  136.         while(current!=NULL)
  137.         {
  138.             i++;
  139.             printf("\nid=%d\tnazwa=%s\tliczba prob=%d\tgodzina rozpoczecia=%.2lf",current->id, current->name, current->trying, current->startTime);
  140.             current=current->next;
  141.         }
  142.     }
  143. }
  144. void FromFileToListPlayer(PLAYER **first)
  145. {
  146.  
  147.     FILE* file=fopen("Gracze.txt","r");
  148.     if(file==NULL)
  149.     {
  150.         printf("\nNie udalo sie otworzyc pliku z informacjami o zawodnikach");
  151.     }
  152.     else
  153.     {
  154.         char table[100];
  155.         int i, j=0;
  156.         char NAME[100];
  157.         for(i=0;i<100;i++)
  158.         {
  159.            NAME[i]=NULL;
  160.         }
  161.         char SURNAME[100];
  162.         for(i=0;i<100;i++)
  163.         {
  164.             SURNAME[i]=NULL;
  165.         }
  166.         char YEAR[100];
  167.         for(i=0;i<100;i++)
  168.         {
  169.             YEAR[i]=NULL;
  170.         }
  171.         char CITY[100];
  172.         for(i=0;i<100;i++)
  173.         {
  174.             CITY[i]=NULL;
  175.         }
  176.         char ID[100];
  177.         for(i=0;i<100;i++)
  178.         {
  179.             ID[i]=NULL;
  180.         }
  181.         int year, id;
  182.         while(fscanf(file,"%s",table)!=EOF)
  183.         {
  184.             if (j==0)
  185.             {
  186.                 strcpy(ID,table);
  187.                 id=atoi(ID);
  188.             }
  189.             else if(j==1)
  190.             {
  191.                 strcpy(NAME,table);
  192.             }
  193.             else if(j==2)
  194.             {
  195.                 strcpy(SURNAME,table);
  196.             }
  197.             else if(j==3)
  198.             {
  199.                 strcpy(YEAR,table);
  200.                 year=atoi(YEAR);
  201.             }
  202.             else if(j==4)
  203.             {
  204.                 strcpy(CITY,table);
  205.                 AddPlayer(first,NAME,SURNAME,CITY,year,id);
  206.             }
  207.             j++;
  208.             if(j==5)
  209.             {
  210.                 j=0;
  211.             }
  212.         }
  213.         fclose(file);
  214.     }
  215. }
  216. void FromFileToListCompetition(COMPETITION **first)
  217. {
  218.     FILE* file2=fopen("Konkurencje.txt","r");
  219.     if(file2==NULL)
  220.     {
  221.         printf("\nNie udalo sie otworzyc pliku z informacjami na temat konkurencji");
  222.     }
  223.     else
  224.     {
  225.         char table[100];
  226.         int i, j=0;
  227.         char NAME[100];
  228.         for(i=0;i<100;i++)
  229.         {
  230.            NAME[i]=NULL;
  231.         }
  232.         char STARTTIME[100];
  233.         for(i=0;i<100;i++)
  234.         {
  235.             STARTTIME[i]=NULL;
  236.         }
  237.         char TRYING[100];
  238.         for(i=0;i<100;i++)
  239.         {
  240.             TRYING[i]=NULL;
  241.         }
  242.         char ID[100];
  243.         for(i=0;i<100;i++)
  244.         {
  245.             ID[i]=NULL;
  246.         }
  247.         int trying,id;
  248.         double startTime;
  249.         while(fscanf(file2,"%s",table)!=EOF)
  250.         {
  251.             if(j==0)
  252.             {
  253.                 strcpy(ID,table);
  254.                 id=atoi(ID);
  255.             }
  256.             else if(j==1)
  257.             {
  258.                 strcpy(NAME,table);
  259.             }
  260.             else if(j==2)
  261.             {
  262.                 strcpy(STARTTIME,table);
  263.                 sscanf(STARTTIME,"%lf",&startTime);
  264.             }
  265.             else if(j==3)
  266.             {
  267.                 strcpy(TRYING,table);
  268.                 trying=atoi(TRYING);
  269.                 AddCompetition(first,NAME,trying,startTime,id);
  270.             }
  271.             j++;
  272.             if(j==4)
  273.             {
  274.                 j=0;
  275.             }
  276.         }
  277.         fclose(file2);
  278.     }
  279. }
  280. void FromFileToListFinale(FINALE **firstF, PLAYER **firstP, COMPETITION **firstC)
  281. {
  282.     FILE* file3=fopen("Wyniki.txt","r");
  283.     if(file3==NULL)
  284.     {
  285.         printf("\nNie udalo sie otworzyc pliku zawierajacego wyniki");
  286.     }
  287.     else
  288.     {
  289.         char table[10];
  290.         int i, j=0,k=0,l=0;
  291.         char IDOFPLAYER[10];
  292.         for(i=0;i<10;i++)
  293.         {
  294.            IDOFPLAYER[i]=NULL;
  295.         }
  296.         char IDOFCOMPETITION[10];
  297.         for(i=0;i<10;i++)
  298.         {
  299.             IDOFCOMPETITION[i]=NULL;
  300.         }
  301.         char TIME[10];
  302.         for(i=0;i<10;i++)
  303.         {
  304.             TIME[i]=NULL;
  305.         }
  306.         int idp,idc;
  307.         double time[5];
  308.         for(i=0;i<5;i++)
  309.         {
  310.             time[i]=0;
  311.         }
  312.         while(fscanf(file3,"%s",table)!=EOF)
  313.         {
  314.             if(j==0)
  315.             {
  316.                 strcpy(IDOFPLAYER,table);
  317.                 idp=atoi(IDOFPLAYER);
  318.                 j++;
  319.             }
  320.             else if(j==1)
  321.             {
  322.                 strcpy(IDOFCOMPETITION,table);
  323.                 idc=atoi(IDOFCOMPETITION);
  324.                 j++;
  325.             }
  326.             else if(j==2)
  327.             {
  328.                 if(idc==1)
  329.                 {
  330.                     sscanf(table,"%lf",&time[0]);
  331.                     if(time[0]!=0)
  332.                     {
  333.                         j++;
  334.                         k=1;
  335.                     }
  336.                 }
  337.                 else if(idc==2)
  338.                 {
  339.                     sscanf(table,"%lf",&time[l]);
  340.                     l++;
  341.                     if(time[1]!=0)
  342.                     {
  343.                         j++;
  344.                         k=1;
  345.                     }
  346.                 }
  347.                 else if(idc==3)
  348.                 {
  349.                     sscanf(table,"%lf",&time[l]);
  350.                     l++;
  351.                     if(time[2]!=0)
  352.                     {
  353.                         j++;
  354.                         k=1;
  355.                     }
  356.                 }
  357.                 else if(idc==4)
  358.                 {
  359.                     sscanf(table,"%lf",&time[l]);
  360.                     l++;
  361.                     if(time[3]!=0)
  362.                     {
  363.                         j++;
  364.                         k=1;
  365.                     }
  366.                 }
  367.                 else if(idc==5)
  368.                 {
  369.                     sscanf(table,"%lf",&time[l]);
  370.                     l++;
  371.                     if(time[4]!=0)
  372.                     {
  373.                         j++;
  374.                         k=1;
  375.                     }
  376.                 }
  377.             }
  378.             if(k==1)
  379.             {
  380.                 AddFinale(firstF,firstP,firstC,time,idp,idc);
  381.                 l=0;
  382.                 k=0;
  383.                 for(i=0;i<5;i++)
  384.                 {
  385.                     time[i]=0;
  386.                 }
  387.             }
  388.             if(j==3)
  389.             {
  390.                 j=0;
  391.             }
  392.         }
  393.         fclose(file3);
  394.     }
  395. }
  396. FINALE *CreateFinale(PLAYER **firstP, COMPETITION **firstC, double time[5], int idOfPlayer, int idOfCompetition)
  397. {
  398.     FINALE *item=(FINALE*)malloc(sizeof(FINALE));
  399.     item->player=FindPlayer(*firstP,idOfPlayer);
  400.     item->competition=FindCompetition(*firstC,idOfCompetition);
  401.     strcpy(item->time,time);
  402.     item->next=NULL;
  403.     return item;
  404. }
  405. void AddFinale(FINALE ** firstF,PLAYER **firstP, COMPETITION **firstC, double time[5], int idOfPlayer, int idOfCompetition)
  406. {
  407.     FINALE *item = CreateFinale(firstP,firstC,time,idOfPlayer,idOfCompetition);
  408.     FINALE *pom = *firstF;
  409.     if(*firstF == NULL)
  410.     {
  411.         *firstF = item;
  412.     }
  413.     else
  414.     {
  415.         while(pom->next != NULL)
  416.         {
  417.             pom=pom->next;
  418.         }
  419.         pom->next = item;
  420.     }
  421. }
  422. void printAllFinales(FINALE *first)
  423. {
  424.     if(first==NULL)
  425.     {
  426.         printf("\nBrak informacji na temat wynikow.");
  427.     }
  428.     else
  429.     {
  430.         FINALE *current=first;
  431.         int i=0;
  432.         printf("\n");
  433.         while(current!=NULL)
  434.         {
  435.             i++;
  436.             if(current->competition->id==1)
  437.             {
  438.                 printf("Id gracza -> %d Id Konkurencji -> %d Czas 1 -> %.2lfs\n", current->player->id, current->competition->id, current->time[0]);
  439.             }
  440.             if(current->competition->id==2)
  441.             {
  442.                 printf("Id gracza -> %d Id Konkurencji -> %d Czas 1 -> %.2lfs Czas 2 -> %.2lfs\n", current->player->id, current->competition->id, current->time[0], current->time[1]);
  443.             }
  444.             if(current->competition->id==3)
  445.             {
  446.                 printf("Id gracza -> %d Id Konkurencji -> %d Czas 1 -> %.2lfs Czas 2 -> %.2lfs Czas 3 -> %.2lfs\n", current->player->id, current->competition->id, current->time[0], current->time[1], current->time[2]);
  447.             }
  448.             if(current->competition->id==4)
  449.             {
  450.                 printf("Id gracza -> %d Id Konkurencji -> %d Czas 1 -> %.2lfs Czas 2 -> %.2lfs Czas 3 -> %.2lfs Czas 4 -> %.2lfs\n", current->player->id, current->competition->id, current->time[0], current->time[1], current->time[2], current->time[3]);
  451.             }
  452.             if(current->competition->id==5)
  453.             {
  454.                 printf("Id gracza -> %d Id Konkurencji -> %d Czas 1 -> %.2lfs Czas 2 -> %.2lfs Czas 3 -> %.2lfs Czas 4 -> %.2lfs Czas 5 -> %.2lfs\n", current->player->id, current->competition->id, current->time[0], current->time[1], current->time[2], current->time[3], current->time[4]);
  455.             }
  456.             current=current->next;
  457.         }
  458.     }
  459. }
  460. void A_ForEveryCompetitionPrintPlayersAndTheirAverageScore(FINALE *firstF,COMPETITION *firstC)
  461. {
  462.     if((firstF==NULL) || (firstC==NULL))
  463.     {
  464.         printf("\nNie jest mozliwe wypisanie tego raportu, z powodu braku danych.");
  465.     }
  466.     else
  467.     {
  468.         printf("\n");
  469.         FINALE *currentF=firstF;
  470.         COMPETITION *currentC=firstC;
  471.         FILE* fileA=fopen("a.txt","w");
  472.         int i,j=0,numberOfPlayers=0;
  473.         double suma=0,averageScore,sumaOfAverageScore=0,averageScoreOfAll;
  474.         while(currentC!=NULL)
  475.         {
  476.             printf("Konkurencja %s Liczba prob=%d Godzina rozpoczecia %.2lf\n",currentC->name,currentC->trying,currentC->startTime);
  477.             fprintf(fileA,"Konkurencja %s Liczba prob=%d Godzina rozpoczecia %.2lf\n",currentC->name,currentC->trying,currentC->startTime);
  478.             while(currentF!=NULL)
  479.             {
  480.                 if(currentC->id==currentF->competition->id)
  481.                 {
  482.                     printf("-> Imie i nazwisko: %s %s Miasto: %s Rok urodzenia %d\n",currentF->player->name, currentF->player->surname, currentF->player->city, currentF->player->yearOfBirth);
  483.                     fprintf(fileA,"-> Imie i nazwisko: %s %s Miasto: %s Rok urodzenia %d\n",currentF->player->name, currentF->player->surname, currentF->player->city, currentF->player->yearOfBirth);
  484.                     for(i=0;i<5;i++)
  485.                     {
  486.                         if(currentF->time[i]!=0)
  487.                         {
  488.                             suma=suma+currentF->time[i];
  489.                             j++;
  490.                         }
  491.                     }
  492.                     averageScore=suma/j;
  493.                     printf("\t Sredni czas-> %.2lfs\n", averageScore);
  494.                     fprintf(fileA,"\t Sredni czas-> %.2lfs\n", averageScore);
  495.                     suma=0;
  496.                     j=0;
  497.                     numberOfPlayers++;
  498.                 }
  499.                 sumaOfAverageScore=sumaOfAverageScore+averageScore;
  500.                 averageScore=0;
  501.                 currentF=currentF->next;
  502.             }
  503.             averageScoreOfAll=sumaOfAverageScore/numberOfPlayers;
  504.             printf("Liczba graczy w konkurencji=%d, a ich sredni czas w konkurencji %s to %.2lf",numberOfPlayers,currentC->name, averageScoreOfAll);
  505.             fprintf(fileA,"Liczba graczy w konkurencji=%d, a ich sredni czas w konkurencji %s to %.2lf",numberOfPlayers,currentC->name, averageScoreOfAll);
  506.             sumaOfAverageScore=0;
  507.             averageScoreOfAll=0;
  508.             numberOfPlayers=0;
  509.             currentF=firstF;
  510.             currentC=currentC->next;
  511.             printf("\n\n");
  512.             fprintf(fileA,"\n\n");
  513.         }
  514.         fclose(fileA);
  515.         printf("\n");
  516.     }
  517. }
  518. void B_ForEveryPlayerPrintCompetitionAndHimAverageScoreInAllCompetitions(FINALE *firstF,PLAYER *firstP)
  519. {
  520.     if((firstF==NULL) || (firstP==NULL))
  521.     {
  522.         printf("\nNie jest mozliwe wypisanie tego raportu, z powodu braku danych.");
  523.     }
  524.     else
  525.     {
  526.         printf("\n");
  527.         FINALE *currentF=firstF;
  528.         PLAYER *currentP=firstP;
  529.         FILE* fileB=fopen("b.txt","w");
  530.         int i,j=0;
  531.         double suma=0,averageScore;
  532.         while(currentP!=NULL)
  533.         {
  534.             printf("Imie i nazwisko: %s %s Miasto %s Rok urodzenia %d \n",currentP->name,currentP->surname,currentP->city,currentP->yearOfBirth);
  535.             fprintf(fileB,"Imie i nazwisko: %s %s Miasto %s Rok urodzenia %d \n",currentP->name,currentP->surname,currentP->city,currentP->yearOfBirth);
  536.             while(currentF!=NULL)
  537.             {
  538.                 if(currentP->id==currentF->player->id)
  539.                 {
  540.                     printf("-> Konkurencja: %s Liczba prob=%d Godzina rozpoczecia %.2lf\n",currentF->competition->name, currentF->competition->trying, currentF->competition->startTime);
  541.                     fprintf(fileB,"-> Konkurencja: %s Liczba prob=%d Godzina rozpoczecia %.2lf\n",currentF->competition->name, currentF->competition->trying, currentF->competition->startTime);
  542.                     for(i=0;i<5;i++)
  543.                     {
  544.                         if(currentF->time[i]!=0)
  545.                         {
  546.                             suma=suma+currentF->time[i];
  547.                             j++;
  548.                         }
  549.                     }
  550.                     averageScore=suma/j;
  551.                     printf("\t Sredni czas-> %.2lfs\n", averageScore);
  552.                     fprintf(fileB,"\t Sredni czas-> %.2lfs\n", averageScore);
  553.                     suma=0;
  554.                     averageScore=0;
  555.                     j=0;
  556.                 }
  557.                 currentF=currentF->next;
  558.             }
  559.             currentF=firstF;
  560.             currentP=currentP->next;
  561.             printf("\n");
  562.             fprintf(fileB,"\n");
  563.         }
  564.         fclose(fileB);
  565.         printf("\n");
  566.     }
  567. }
  568. void C_FindPlayerWhoStartedInTheHighestNumberOfCompetition(FINALE *firstF,PLAYER *firstP)
  569. {
  570.     if((firstF==NULL) || (firstP)==NULL)
  571.     {
  572.         printf("\nNie jest mozliwe wypisanie tego raportu, z powodu braku danych.");
  573.     }
  574.     else
  575.     {
  576.         printf("\n");
  577.         FINALE *currentF=firstF;
  578.         PLAYER *currentP=firstP;
  579.         FILE* fileC=fopen("c.txt","w");
  580.         int tableOfPlayer[1000];
  581.         int tableOfPlayer2[1000];
  582.         int i,j,max=0;
  583.         int who;
  584.         for(i=0;i<1000;i++)
  585.         {
  586.             tableOfPlayer[i]=0;
  587.             tableOfPlayer2[i]=0;
  588.         }
  589.         while(currentF!=NULL)
  590.         {
  591.             tableOfPlayer[currentF->player->id]++;
  592.             currentF=currentF->next;
  593.         }
  594.         for(i=0;i<1000;i++)
  595.         {
  596.             //printf("Gracz id %d wynik %d\n",i, tableOfPlayer[i]);
  597.         }
  598.         for(i=0;i<1000;i++)
  599.         {
  600.             if(tableOfPlayer[i]>max)
  601.             {
  602.                 max=tableOfPlayer[i];
  603.             }
  604.         }
  605.        // printf("\n%d\n",max);
  606.         j=0;
  607.         for(i=0;i<1000;i++)
  608.         {
  609.             if(tableOfPlayer[i]==max)
  610.             {
  611.                 //printf("id gracza %d\n", i);
  612.                 tableOfPlayer2[j]=i;
  613.                 j++;
  614.             }
  615.         }
  616.         printf("Gracz ktory wzial udzial w najwiekszej ilosci konkurencji to\n");
  617.         fprintf(fileC,"Gracz ktory wzial udzial w najwiekszej ilosci konkurencji to\n");
  618.         for(i=0;i<1000;i++)
  619.         {
  620.             if(tableOfPlayer2[i]!=0)
  621.             {
  622.                 //printf("Numer w tabeli %d ID %d", i, tableOfPlayer2[i]);
  623.                 currentP=FindPlayer(firstP,tableOfPlayer2[i]);
  624.                 printf("Imie:%s Nazwisko:%s Miasto:%s Rok Urodzenia=%d Liczba Konkurencji=%d\n", currentP->name,currentP->surname,currentP->city,currentP->yearOfBirth,max);
  625.                 fprintf(fileC,"Imie:%s Nazwisko:%s Miasto:%s Rok Urodzenia=%d Liczba Konkurencji=%d\n", currentP->name,currentP->surname,currentP->city,currentP->yearOfBirth,max);
  626.             }
  627.         }
  628.         fclose(fileC);
  629.         printf("\n");
  630.     }
  631. }
  632. void D_ForGivenPlayerPrintTheBestScoreInAllCompetitions(FINALE *firstF, PLAYER *firstP, int idOfPlayer)
  633. {
  634.     if((firstF==NULL) || (firstP)==NULL)
  635.     {
  636.         printf("\nNie jest mozliwe wypisanie tego raportu, z powodu braku danych.");
  637.     }
  638.     else
  639.     {
  640.         printf("\n");
  641.         FINALE *currentF=firstF;
  642.         PLAYER *currentP=firstP;
  643.         FILE* fileD=fopen("d.txt","w");
  644.         currentP=FindPlayer(firstP,idOfPlayer);
  645.         printf("Imie i nazwisko %s %s Miasto %s Rok urodzenia %d\n", currentP->name,currentP->surname,currentP->city,currentP->yearOfBirth);
  646.         fprintf(fileD,"Imie i nazwisko %s %s Miasto %s Rok urodzenia %d\n", currentP->name,currentP->surname,currentP->city,currentP->yearOfBirth);
  647.         double min=999999;
  648.         int i;
  649.         while(currentF!=NULL)
  650.         {
  651.             if(currentF->player->id==idOfPlayer)
  652.             {
  653.                 if(currentF->competition->id==1)
  654.                 {
  655.                     for(i=0;i<1;i++)
  656.                     {
  657.                         if(currentF->time[i]<min)
  658.                         {
  659.                             min=currentF->time[i];
  660.                         }
  661.                     }
  662.                 }
  663.                 else if(currentF->competition->id==2)
  664.                 {
  665.                     for(i=0;i<2;i++)
  666.                     {
  667.                         if(currentF->time[i]<min)
  668.                         {
  669.                             min=currentF->time[i];
  670.                         }
  671.                     }
  672.                 }
  673.                 else if(currentF->competition->id==3)
  674.                 {
  675.                     for(i=0;i<3;i++)
  676.                     {
  677.                         if(currentF->time[i]<min)
  678.                         {
  679.                             min=currentF->time[i];
  680.                         }
  681.                     }
  682.                 }
  683.                 else if(currentF->competition->id==4)
  684.                 {
  685.                     for(i=0;i<4;i++)
  686.                     {
  687.                         if(currentF->time[i]<min)
  688.                         {
  689.                             min=currentF->time[i];
  690.                         }
  691.                     }
  692.                 }
  693.                 else if(currentF->competition->id==5)
  694.                 {
  695.                     for(i=0;i<5;i++)
  696.                     {
  697.                         if(currentF->time[i]<min)
  698.                         {
  699.                             min=currentF->time[i];
  700.                         }
  701.                     }
  702.                 }
  703.                 printf("->Najlepszy czas w konkurencji %s %.2lfs\n",currentF->competition->name, min);
  704.                 fprintf(fileD,"->Najlepszy czas w konkurencji %s %.2lfs\n",currentF->competition->name, min);
  705.                 min=999999;
  706.             }
  707.             currentF=currentF->next;
  708.         }
  709.         fclose(fileD);
  710.         printf("\n");
  711.     }
  712. }
  713. void E_CalculateHowManyCompetitionsForEveryPlayer(FINALE *firstF,PLAYER *firstP)
  714. {
  715.     if((firstF==NULL) || (firstP)==NULL)
  716.     {
  717.         printf("\nNie jest mozliwe wypisanie tego raportu, z powodu braku danych.");
  718.     }
  719.     else
  720.     {
  721.         printf("\n");
  722.         PLAYER *currentP=firstP;
  723.         FINALE *currentF=firstF;
  724.         FILE *fileE=fopen("e.txt","w");
  725.         int howManyCompetition=0;
  726.         int howManyPlayers=0;
  727.         double score;
  728.         while(currentP!=NULL)
  729.         {
  730.             howManyPlayers++;
  731.             currentP=currentP->next;
  732.         }
  733.         while(currentF!=NULL)
  734.         {
  735.  
  736.             howManyCompetition++;
  737.             currentF=currentF->next;
  738.         }
  739.         score=(double)howManyCompetition/(double)howManyPlayers;
  740.         printf("W zawodach wzielo udzial %d graczy, laczna liczba startow w konkurencjach to %d.\nSrednio przypadlo %.2lf startu na zawodnika.\n", howManyPlayers, howManyCompetition, score);
  741.         fprintf(fileE,"W zawodach wzielo udzial %d graczy, laczna liczba startow w konkurencjach to %d.\nSrednio przypadlo %.2lf startu na zawodnika.\n", howManyPlayers, howManyCompetition, score);
  742.         fclose(fileE);
  743.         printf("\n");
  744.     }
  745. }
  746. void F_ForEveryPlayerFindCompetitionInWhichWasFiveTryingAndDifferenceBetweenTheWorstScoreAndTheBestScoreWasLowerThanGivenValue(FINALE *firstF,PLAYER *firstP,double value)
  747. {
  748.     if((firstF==NULL) || (firstP)==NULL)
  749.     {
  750.         printf("\nNie jest mozliwe wypisanie tego raportu, z powodu braku danych.");
  751.     }
  752.     else
  753.     {
  754.         printf("\n");
  755.         FINALE *currentF=firstF;
  756.         PLAYER *currentP=firstP;
  757.         FILE *fileF=fopen("f.txt","w");
  758.         double max=0,min=999999;
  759.         int i;
  760.         printf("Zawodnicy, ktorzy wzieli udzial w konkurencjach, w ktorych bylo 5 prob:\n");
  761.         fprintf(fileF,"Zawodnicy, ktorzy wzieli udzial w konkurencjach, w ktorych bylo 5 prob:\n");
  762.         while(currentP!=NULL)
  763.         {
  764.             while(currentF!=NULL)
  765.             {
  766.                 if(currentF->competition->trying==5)
  767.                 {
  768.                     for(i=0;i<5;i++)
  769.                     {
  770.                         if(currentF->time[i]<min)
  771.                         {
  772.                             min=currentF->time[i];
  773.                         }
  774.                     }
  775.                     for(i=0;i<5;i++)
  776.                     {
  777.                         if(currentF->time[i]>max)
  778.                         {
  779.                             max=currentF->time[i];
  780.                         }
  781.                     }
  782.                     printf("-> %s %s ( %s ), jego najlepszy czas to %.2lf, a najgorszy to %.2lf",currentF->player->name, currentF->player->surname,currentF->competition->name,min,max);
  783.                     fprintf(fileF,"-> %s %s ( %s ), jego najlepszy czas to %.2lf, a najgorszy to %.2lf",currentF->player->name, currentF->player->surname,currentF->competition->name,min,max);
  784.                     if(max-min<value)
  785.                     {
  786.                         printf(" - Roznica miedzy czasem najlepszym a najgorszym jest mniejsza od zadanej wartosci (%.2lf)\n",value);
  787.                         fprintf(fileF," - Roznica miedzy czasem najlepszym a najgorszym jest mniejsza od zadanej wartosci (%.2lf)\n",value);
  788.                     }
  789.                     else
  790.                     {
  791.                         printf("\n");
  792.                         fprintf(fileF,"\n");
  793.                     }
  794.                     max=0,min=999999;
  795.                 }
  796.                 currentF=currentF->next;
  797.             }
  798.             currentP=currentP->next;
  799.         }
  800.         currentF=firstF;
  801.         currentP=firstP;
  802.  
  803.         while(currentP!=NULL)
  804.         {
  805.             while(currentF!=NULL)
  806.             {
  807.  
  808.                 currentF=currentF->next;
  809.             }
  810.             currentP=currentP->next;
  811.         }
  812.     fclose(fileF);
  813.     }
  814. }
  815. void Menu(FINALE *firstF,PLAYER *firstP,COMPETITION *firstC)
  816. {
  817.     char x;
  818.     int who;
  819.     double value;
  820.     printf("Wybierz raport z zawodow KOSTKA RUBIKA, ktory chcesz wykonac?\n");
  821.     printf("A -> Dla kazdej konkurencji wypisze liste zawodnikow i ich sredni wynik.\n");
  822.     printf("B -> Dla kazdego zawodnika wypisz wszystkie konkurencje i jego sredni wynik w kazdej konkurencji.\n");
  823.     printf("C -> Znajdz zawodnika/ow, ktory/rzy wzial/eli udzial w najwiekszej liczbie konkurencji.\n");
  824.     printf("D -> Dla podanego zawodnika wypisz wynik najlepszej proby (najmniejszy czas) w kazdej konkurencji.\n");
  825.     printf("E -> Oblicz, ile srednio konkurencji przypadlo na kazdego zawodnika.\n");
  826.     printf("F -> Dla kazdego zawodnika znajdz konkurencje, w ktorych bylo 5 prob, a roznica miedzy najgorsza, a najlepsza proba byla mniejsza od zadanej wartosci.\n");
  827.     printf("G -> Wypisz 3 listy, zawodnikow, konkurencji oraz wynikow.\n");
  828.     printf("H -> Wykonaj wszystkie raporty od A do F.\n");
  829.     scanf("%c",&x);
  830.     switch (x)
  831.     {
  832.         case 'A': A_ForEveryCompetitionPrintPlayersAndTheirAverageScore(firstF,firstC);
  833.             Action(firstF,firstP,firstC);
  834.             break;
  835.         case 'B': B_ForEveryPlayerPrintCompetitionAndHimAverageScoreInAllCompetitions(firstF,firstP);
  836.             Action(firstF,firstP,firstC);
  837.             break;
  838.         case 'C': C_FindPlayerWhoStartedInTheHighestNumberOfCompetition(firstF,firstP);
  839.             Action(firstF,firstP,firstC);
  840.             break;
  841.         case 'D':
  842.             printf("\nDla ktorego? Podaj ID zawodnika ");
  843.             scanf("%d", &who);
  844.             D_ForGivenPlayerPrintTheBestScoreInAllCompetitions(firstF,firstP,who);
  845.             Action(firstF,firstP,firstC);
  846.             break;
  847.         case 'E': E_CalculateHowManyCompetitionsForEveryPlayer(firstF,firstP);
  848.             Action(firstF,firstP,firstC);
  849.             break;
  850.         case 'F':
  851.             printf("\nPodaj wartosc roznicy miedzy najgorsza a najlepsza proba ");
  852.             scanf("%lf", &value);
  853.             F_ForEveryPlayerFindCompetitionInWhichWasFiveTryingAndDifferenceBetweenTheWorstScoreAndTheBestScoreWasLowerThanGivenValue(firstF,firstP,value);
  854.             Action(firstF,firstP,firstC);
  855.             break;
  856.         case 'G':
  857.             printAllPlayers(firstP);
  858.             printAllCompetition(firstC);
  859.             printAllFinales(firstF);
  860.             Action(firstF,firstP,firstC);
  861.             break;
  862.         case 'H':
  863.             printf("\t\tRAPORT A:\n");
  864.             A_ForEveryCompetitionPrintPlayersAndTheirAverageScore(firstF,firstC);
  865.             printf("\t\tRAPORT B:\n");
  866.             B_ForEveryPlayerPrintCompetitionAndHimAverageScoreInAllCompetitions(firstF,firstP);
  867.             printf("\t\tRAPORT C:\n");
  868.             C_FindPlayerWhoStartedInTheHighestNumberOfCompetition(firstF,firstP);
  869.             printf("\t\tRAPORT D:\n");
  870.             printf("\nDla ktorego? Podaj ID zawodnika ");
  871.             scanf("%d", &who);
  872.             D_ForGivenPlayerPrintTheBestScoreInAllCompetitions(firstF,firstP,who);
  873.             printf("\t\tRAPORT E:\n");
  874.             E_CalculateHowManyCompetitionsForEveryPlayer(firstF,firstP);
  875.             printf("\t\tRAPORT F:\n");
  876.             printf("\nPodaj wartosc roznicy miedzy najgorsza a najlepsza proba ");
  877.             scanf("%lf", &value);
  878.             F_ForEveryPlayerFindCompetitionInWhichWasFiveTryingAndDifferenceBetweenTheWorstScoreAndTheBestScoreWasLowerThanGivenValue(firstF,firstP,value);
  879.             Action(firstF,firstP,firstC);
  880.             break;
  881.         default:
  882.             system("cls");
  883.             Menu(firstF,firstP,firstC);
  884.     }
  885. }
  886. void Action(FINALE *firstF,PLAYER *firstP,COMPETITION *firstC)
  887. {
  888.             char action[3];
  889.             printf("\nCo dalej? Aby wylaczyc program wpisz END, aby kontynuowac wpisz cokolwiek: \n");
  890.             scanf("%s",action);
  891.             if((action[0]==69) && (action[1]==78) && (action[2]==68))
  892.             {
  893.                 exit(0);
  894.             }
  895.             else
  896.             {
  897.                 system("cls");
  898.                 Menu(firstF,firstP,firstC);
  899.             }
  900. }
  901. int main()
  902. {
  903.     PLAYER *firstP=NULL;
  904.     COMPETITION *firstC=NULL;
  905.     FINALE *firstF=NULL;
  906.     FromFileToListPlayer(&firstP);
  907.     FromFileToListCompetition(&firstC);
  908.     FromFileToListFinale(&firstF,&firstP,&firstC);
  909.     Menu(firstF,firstP,firstC);
  910.     return 0;
  911. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement