Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/132/13287/c.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 
   33 void init()
   34 {
   35     /* FUNCTION init */
   36 } /* FUNCTION init */
   37 
   38 void dump()
   39 {
   40     /* FUNCTION dump */
   41 } /* FUNCTION dump */
   42 
   43 int getnum()
   44 {
   45     /* FUNCTION getNum */
   46     int num = 0;
   47     char x;
   48 
   49     x = getchar();
   50     while (isspace(x))
   51         {
   52             x = getchar();
   53         }
   54     while (isdigit(x))
   55         {
   56             /* while */
   57             num = (num * 10) + x - '0';
   58             x = getchar();
   59         } /* while */
   60     return num;
   61 } /* FUNCTION getNum */
   62 
   63 int getInput()
   64 {
   65     /* FUANCTION getInput */
   66     int i;
   67     int x;
   68     int y;
   69     int cnt;
   70     int moreToDo;
   71 
   72     moreToDo = 0 < (scanf(" %d ", &width));
   73     if (moreToDo)
   74         {
   75             /* read width -- so get rest of data */
   76             tot = 0;
   77             scanf(" %d ", &cnt);
   78             DEBUG printf("(width = %d)  (cnt = %d)  (tot = %d)\n", width, cnt, tot);
   79             for (i=0; cnt>i; i++)
   80                 {
   81                     /*  for */
   82                     /*
   83                       scanf(" %d %d ", &x, &y);
   84                     */
   85                     x = getnum();
   86                     y = getnum();
   87                     tot = tot + (x * y);
   88                 } /*  for */
   89             DEBUG printf("(width = %d)  (cnt = %d)  (tot = %d)\n", width, cnt, tot);
   90         } /* read width -- so get rest of data */
   91     return moreToDo;
   92 } /* FUNCTION getInput */
   93 
   94 void process()
   95 {
   96     /* FUNCTION process */
   97     lgth = tot / width;
   98     printf("%d\n", lgth);
   99 } /* FUNCTION process */
  100 
  101 int main()
  102 {
  103     /* main */
  104     int i;
  105 
  106     moreToDo = getInput();
  107     while (moreToDo)
  108         {
  109             /* while */
  110             process();
  111             moreToDo = getInput();
  112         } /* while */
  113 
  114     return EXIT_SUCCESS;
  115 } /* main */
  116 
  117