Computer Programming Contest Preparation

ToolBox - Source for: 132/13287/g.c



/home/toolbox/public_html/solutions/132/13287/g.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: 2018-10-23
   20  * Purpose: fun
   21  * Problem: 13287
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 int moreToDo;
   29 int width;
   30 int lgth;
   31 int tot;
   32 int i;
   33 int x;
   34 int cnt;
   35 int num;
   36 char xx;
   37 
   38 void getnum()
   39 {
   40     /* FUNCTION getNum */
   41     xx = getchar_unlocked();
   42     while ((' ' == xx) || ('\n' == xx))
   43         {
   44             xx = getchar_unlocked();
   45         }
   46     num = xx - '0';
   47     xx = getchar_unlocked();
   48     while (('0' <= xx) && ('9' >= xx))
   49         {
   50             /* while */
   51             /*
   52               num = (num * 10) + x - '0';
   53               num * 10 == (num * 8) + (num * 2)
   54               num << 3 == num * 8
   55               num << 1 == num * 2
   56             */
   57             num = (num << 3) + (num << 1) + xx - '0';
   58             xx = getchar_unlocked();
   59         } /* while */
   60 } /* FUNCTION getNum */
   61 
   62 void getInput()
   63 {
   64     /* FUNCTION getInput */
   65 
   66     moreToDo = 0 < (scanf(" %d ", &width));
   67     if (moreToDo)
   68         {
   69             /* read width -- so get rest of data */
   70             tot = 0;
   71             getnum();
   72             cnt = num;
   73             for (i=0; cnt>i; i++)
   74                 {
   75                     /*  for */
   76                     getnum();
   77                     x = num;
   78                     getnum();
   79                     tot = tot + (x * num);
   80                 } /*  for */
   81         } /* read width -- so get rest of data */
   82 } /* FUNCTION getInput */
   83 
   84 int main()
   85 {
   86     /* main */
   87 
   88     getInput();
   89     while (moreToDo)
   90         {
   91             /* while */
   92             printf("%d\n", tot / width);
   93             getInput();
   94         } /* while */
   95 
   96     return EXIT_SUCCESS;
   97 } /* main */
   98 
   99