Computer Programming Contest Preparation

ToolBox - Source for: 113/11369/a.c



/home/toolbox/public_html/solutions/113/11369/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: 11369
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define MAX_ITEMS 20005
   29 
   30 int numberOfTimes;
   31 int numItems;
   32 int items[MAX_ITEMS+1];
   33 
   34 void init()
   35 {
   36     /* FUNCTION init */
   37     scanf("%d ", &numberOfTimes);
   38 } /* FUNCTION init */
   39 
   40 void dump()
   41 {
   42     /* FUNCTION dump */
   43 } /* FUNCTION dump */
   44 
   45 int compare(const void *a, const void *b)
   46 {
   47     /* FUNCTION compare */
   48     return ( *(int*)b - *(int*)a );
   49 } /* FUNCTION compare */
   50 
   51 void getInput()
   52 {
   53     /* FUNCTION getInput */
   54     int i;
   55 
   56     scanf("%d ", &numItems);
   57     for (i=0; numItems>i; i++)
   58         {
   59             /* for */
   60             scanf(" %d ", &items[i]);
   61         } /* for */
   62     qsort(items, numItems, sizeof(int), compare);
   63 } /* FUNCTION getInput */
   64 
   65 void process()
   66 {
   67     /* FUNCTION process */
   68     int tot = 0;
   69     int i;
   70 
   71     for (i=2; i<numItems; i=i+3)
   72         {
   73             /* for */
   74             tot = tot + items[i];
   75         } /* for */
   76     printf("%d\n", tot);
   77 
   78 } /* FUNCTION process */
   79 
   80 int main()
   81 {
   82     /* main */
   83     int i;
   84 
   85     init();
   86     for (i=0; i<numberOfTimes; i++)
   87         {
   88             /* while */
   89             getInput();
   90             process();
   91         } /* while */
   92 
   93     return EXIT_SUCCESS;
   94 } /* main */
   95 
   96