Computer Programming Contest Preparation

ToolBox - Source for: 103/10370/a.c



/home/toolbox/public_html/solutions/103/10370/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 #define MAX_GRADES 1005
   15 
   16 /* fprintf(stderr, "functionName: message", varslist); */
   17 
   18 /*
   19  *  Author: Isaac Traxler
   20  *    Date: 2014-10-29
   21  * Purpose: fun
   22  * Problem: 10370 - Above Average
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  */
   28 
   29 int numberOfTimes;
   30 int students;
   31 int grades[MAX_GRADES];
   32 int tot;
   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 void getInput()
   46 {
   47     /* FUNCTION getInput */
   48     int i;
   49 
   50     scanf(" %d ", &students);
   51     tot = 0;
   52     for(i=0; i<students; i++)
   53         {
   54             /* read each grade */
   55             scanf(" %d ", &grades[i]);
   56             tot = tot + grades[i];
   57         } /* read each grade */
   58 } /* FUNCTION getInput */
   59 
   60 void process()
   61 {
   62     /* FUNCTION process */
   63     int i;
   64     double avg;
   65     int cnt = 0;
   66     double above;
   67 
   68     avg = ((double) tot) / ((double) students);
   69     DEBUG printf("avg=%lf  tot=%d   students=%d\n", avg, tot, students);
   70     for (i=0; i<students; i++)
   71         {
   72             /* for each col */
   73             if (grades[i] > avg)
   74                 {
   75                     cnt++;
   76                 }
   77         } /* for each col */
   78     above = 100 * ((double) cnt) / ((double) students);
   79 
   80     printf("%2.3f%%\n", above);
   81 
   82 } /* FUNCTION process */
   83 
   84 int main ()
   85 {
   86     /* main */
   87     int i;
   88 
   89     init();
   90     for (i=0; i<numberOfTimes; i++)
   91         {
   92             /* while */
   93             getInput();
   94             process();
   95         } /* while */
   96 
   97     return EXIT_SUCCESS;
   98 } /* main */
   99 
  100