Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jul 21st, 2018 55 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define NBSPORTIFSMAX 7
  6. #define NBEVENMAX 10
  7. #define NAMELENMAX 33
  8.  
  9. int inputRoutine(char inputNames[NBSPORTIFSMAX][33]);
  10. int getEventsNoRoutine(void);
  11. void inputScoreRoutine(signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX], int events, int names, char inputNames[NBSPORTIFSMAX][NAMELENMAX]);
  12. void min(signed short int minScores[NBEVENMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX]);
  13. void mid(signed short int midScores[NBEVENMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX]);
  14. void max(signed short int maxScores[NBEVENMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX]);
  15. void bestPlayer(signed short int bestScores[NBSPORTIFSMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX]);
  16. void midScores(signed short int midScores[NBSPORTIFSMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX]);
  17. void bubbleSort(short int numbers[NBEVENMAX], int size);
  18. int award(signed short int inputScores[NBEVENMAX], int events);
  19.  
  20. int main(int argc, char **argv)
  21. {
  22.   char inputNames[NBSPORTIFSMAX][NAMELENMAX];
  23.   signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX];
  24.   signed short int maxScores[NBEVENMAX], midScores[NBEVENMAX], mid2Scores[NBSPORTIFSMAX], minScores[NBEVENMAX];
  25.   signed short int bestScores[NBSPORTIFSMAX];
  26.   int i = 0, j = 0, prnVal = 0;
  27.  
  28.   int inputEvents = 0, inputNamesVal = 0;
  29.  
  30.   inputNamesVal = inputRoutine(inputNames);
  31.   while(!inputEvents || inputEvents > NBEVENMAX)
  32.   {
  33.     inputEvents = getEventsNoRoutine( );
  34.     if(inputEvents <= NBEVENMAX && inputEvents > 0)
  35.       break;
  36.     else
  37.       printf("error: there must be more than one event and at most %i events.\n", NBEVENMAX);
  38.   }
  39.   inputScoreRoutine(inputScores, inputEvents, inputNamesVal, inputNames);
  40.   min(minScores, inputEvents, inputNamesVal, inputScores);
  41.   mid(midScores, inputEvents, inputNamesVal, inputScores);
  42.   max(maxScores, inputEvents, inputNamesVal, inputScores);
  43.   midScores(mid2Scores, inputEvents, inputNamesVal, inputScores);
  44.   bestPlayer(bestScores, inputEvents, inputNamesVal, inputScores);
  45.  
  46.     while(1)
  47.     {
  48.         system("cls");
  49.         printf("Enter player who's data to print:\n");
  50.         for(i = 0; i < inputNamesVal; i++)
  51.             printf("\t%i - %s\n", i, inputNames[i]);
  52.         printf("\n\n%i - Best players in each event\n%i - Median of event scores\nX - Exit\n\nEnter option to print: ", i, i+1);
  53.         scanf("%i", &prnVal);
  54.         if(prnVal == inputNamesVal)
  55.         {
  56.             for(j = 0; j < 99; j++)
  57.                     putchar('=');
  58.             for(j = 0; j < inputNamesVal; j++)
  59.                 printf("Event %3i, Winner: %s\n", j + 1, inputNames[bestScores[j]]);
  60.             putchar('\n');
  61.         }
  62.         else if(prnVal == i + 1)
  63.         {
  64.             for(j = 0; j < inputEvents; j++)
  65.                 printf("Event: %i, median: %i\n", j + 1, mid2Scores[j]);
  66.         }
  67.         else if(prnVal == 'X')
  68.             break;
  69.         else
  70.         {
  71.             for(j = 0; j < 99; j++)
  72.                     putchar('=');
  73.             printf("\n%15s | ", "Event ID");
  74.             for(j = 0; j < inputEvents; j++)
  75.                 printf("%3i ", j + 1);
  76.             printf("Min Mid Max Award\n");
  77.             for(j = 0; j < 99; j++)
  78.                 putchar('=');
  79.             putchar('\n');
  80.             printf("%15s | ", inputNames[prnVal]);
  81.             printf("%3i %3i %3i %5s", minScores[prnVal], midScores[prnVal], maxScores[prnVal], (award(inputScores[prnVal], inputEvents)) ? "YES" : "NO");
  82.             putchar('\n');
  83.             for(j = 0; j < 99; j++)
  84.                 putchar('=');
  85.             printf("\n\npress enter to continue...");
  86.             fflush(stdin); getchar( );
  87.         }
  88.     }
  89.   return(0);
  90. }
  91.  
  92. int inputRoutine(char inputNames[NBSPORTIFSMAX][33]) // take argument by full reference since we know the bounds
  93. {
  94.   int i = 0;
  95.   printf("Enter the names of the participants, press enter to finish input:\n");
  96.  
  97.   // store names in buffer
  98.   for(i = 0; i < NBSPORTIFSMAX; i++)
  99.   {
  100.     printf("%.2i: ", i + 1);
  101.     fgets(inputNames[i], NAMELENMAX - 1, stdin);
  102.     if(inputNames[i][0] == '\n') // break if input is blank
  103.       break;
  104.     inputNames[i][(strlen(inputNames[i]) - 1)] = 0; // removes the newline character
  105.   }
  106.   return(i);
  107. }
  108.  
  109. int getEventsNoRoutine(void)
  110. {
  111.   int input;
  112.   printf("Enter number of events: ");
  113.   scanf("%i", &input);
  114.   return(input);
  115. }
  116.  
  117. void inputScoreRoutine(signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX], int events, int names, char inputNames[NBSPORTIFSMAX][NAMELENMAX])
  118. {
  119.   int menuOption, loopControl = 1, i = 0, j = 0;
  120.   system("cls");
  121.   printf("Input Scores Menu\n\nInput by:\n\t0: Participant name\n\t1: Event\n\n");
  122.   while(loopControl)
  123.   {
  124.     printf("Option: ");
  125.     scanf("%i", &menuOption);
  126.     switch(menuOption)
  127.     {
  128.       case 0:
  129.         loopControl ^= loopControl; //Nice touch :P 'cos we are 1337
  130.         system("cls");
  131.         for(i = 0; i < names; i++)
  132.         {
  133.           printf("Input for: %s (%.2i)\n", inputNames[i], i + 1);
  134.           for(j = 0; j < events; j++)
  135.           {
  136.             printf("Event %.2i: ", j + 1);
  137.             scanf("%i", &inputScores[i][j]);
  138.           }
  139.         }
  140.         break;
  141.       case 1:
  142.         loopControl ^= loopControl;
  143.         system("cls");
  144.         for(i = 0; i < events; i++)
  145.         {
  146.           printf("Input for event %.2i:\n", i + 1);
  147.           for(j = 0; j < names; j++)
  148.           {
  149.             printf("Input for %s (%.2i): ", inputNames[j], j + 1);
  150.             scanf("%i", &inputScores[j][i]);
  151.           }
  152.         }
  153.         break;
  154.       default:
  155.         printf("error: invaild menu option.\n");
  156.         break;
  157.     }
  158.   }
  159. }
  160.  
  161. void min(signed short int minScores[NBEVENMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX])
  162. {
  163.   signed short int temp, i = 0, j = 0;
  164.   for(i = 0; i < names; i++)
  165.   {
  166.     temp = inputScores[i][0];
  167.     for(j = 0; j < events; j++)
  168.       if(temp > inputScores[i][j])
  169.         temp = inputScores[i][j];
  170.     minScores[i] = temp;
  171.   }
  172. }
  173.  
  174. void mid(signed short int midScores[NBEVENMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX])
  175. {
  176.   signed short int tempArray[NBEVENMAX], temp, i = 0, j = 0;
  177.   for(i = 0; i < names; i++)
  178.   {
  179.     for(j = 0; j < events; j++)
  180.       tempArray[j] = inputScores[i][j];
  181.     bubbleSort(tempArray, events);
  182.     midScores[i] = tempArray[(int)(events/2)]; // if even will take the lower value
  183.   }
  184.  
  185. }
  186.  
  187. void max(signed short int maxScores[NBEVENMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX])
  188. {
  189.   signed short int temp, i = 0, j = 0;
  190.   for(i = 0; i < names; i++)
  191.   {
  192.     temp = inputScores[i][0];
  193.     for(j = 0; j < events; j++)
  194.       if(temp < inputScores[i][j])
  195.         temp = inputScores[i][j];
  196.     maxScores[i] = temp;
  197.   }
  198. }
  199.  
  200. void bestPlayer(signed short int bestScores[NBSPORTIFSMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX])
  201. {
  202.   int i = 0, j = 0, temp = 0;
  203.   for(i = 0; i < events; i++)
  204.   {
  205.     temp = inputScores[0][i];
  206.     for(j = 0; j < names; j++)
  207.       if(temp > inputScores[j][i])
  208.         temp = inputScores[j][i];
  209.     bestScores[i] = temp;
  210.   }
  211. }
  212.  
  213. int award(signed short int inputScores[NBEVENMAX], int events)
  214. {
  215.   int i = 0, temp;
  216.   temp = inputScores[i];
  217.   for(i = 1; i < events; i++)
  218.   {
  219.     if(temp > inputScores[i])
  220.       break;
  221.     else
  222.     {
  223.       temp = inputScores[i];
  224.       continue;
  225.     }
  226.   }
  227.   return((i == events) ? 1 : 0);
  228. }
  229.  
  230.  
  231. void bubbleSort(short int numbers[NBEVENMAX], int size)
  232. {
  233.   int i, j, temp;
  234.   for(i = (size - 1); i >= 0; i--)
  235.   {
  236.     for(j = 1; j <= i; j++)
  237.     {
  238.       if(numbers[j-1] > numbers[j])
  239.  
  240.       {
  241.               temp = numbers[j-1];
  242.         numbers[j-1] = numbers[j];
  243.         numbers[j] = temp;
  244.       }
  245.     }
  246.   }
  247. }
  248.  
  249. void midScores(signed short int midScores[NBSPORTIFSMAX], int events, int names, signed short int inputScores[NBSPORTIFSMAX][NBEVENMAX]);
  250. {
  251.   signed short int tempArray[NBSPORTIFSMAX], temp, i = 0, j = 0;
  252.   for(i = 0; i < events; i++)
  253.   {
  254.     for(j = 0; j < names; j++)
  255.       tempArray[j] = inputScores[j][i];
  256.     bubbleSort(tempArray, names);
  257.     midScores[i] = tempArray[(int)(names/2)]; // if even will take the lower value
  258.   }
  259.  
  260. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top