Computer Programming Contest Preparation

ToolBox - Source for: 119/11900/a.c



/home/toolbox/public_html/solutions/119/11900/a.c
    1 #include <stdio.h>
    2 #include <string.h>
    3 #include <sys/types.h>
    4 #include <sys/stat.h>
    5 #include <fcntl.h>
    6 #include <stdlib.h>
    7 #include <math.h>
    8 #include <stdint.h>
    9 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /* fprintf(stderr, "functionName: message", varslist); */
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2020-09-29
   20  * Purpose: fun
   21  * Problem: 11900
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define MAX_EGGS 33
   29 
   30 int numberOfTimes;
   31 int numEggs;
   32 int weights[MAX_EGGS+1];
   33 int eggsPerBowl;
   34 int maxWeight;
   35 
   36 void init()
   37 {
   38     /* FUNCTION init */
   39     scanf("%d ", &numberOfTimes);
   40 } /* FUNCTION init */
   41 
   42 void dump()
   43 {
   44     /* FUNCTION dump */
   45 } /* FUNCTION dump */
   46 
   47 int compare(const void *a, const void *b)
   48 {
   49     /* FUNCTION compare */
   50     return ( *(int*)a - *(int*)b );
   51 } /* FUNCTION compare */
   52 
   53 void getInput()
   54 {
   55     /* FUNCTION getInput */
   56     int i;
   57 
   58     scanf(" %d %d %d ", &numEggs, &eggsPerBowl, &maxWeight);
   59     for (i=0; numEggs>i; i++)
   60         {
   61             /* for */
   62             scanf(" %d ", &weights[i]);
   63         } /* for */
   64     qsort(weights, numEggs, sizeof(int), compare);
   65 } /* FUNCTION getInput */
   66 
   67 void process()
   68 {
   69     /* FUNCTION process */
   70     int tot = 0;
   71     int i;
   72     int tmp;
   73 
   74     /* figure out maximum number of eggs we can try */
   75     tmp = (numEggs > eggsPerBowl) ? eggsPerBowl : numEggs;
   76 
   77     for (i=0; (i<tmp) && ((tot + weights[i]) <= maxWeight); i++)
   78         {
   79             /* for */
   80             tot = tot + weights[i];
   81         } /* for */
   82     printf("%d\n", i);
   83 
   84 } /* FUNCTION process */
   85 
   86 int main()
   87 {
   88     /* main */
   89     int i;
   90 
   91     init();
   92     for (i=0; i<numberOfTimes; i++)
   93         {
   94             /* while */
   95             getInput();
   96             printf("Case %d: ", i+1);
   97             process();
   98         } /* while */
   99 
  100     return EXIT_SUCCESS;
  101 } /* main */
  102 
  103