Computer Programming Contest Preparation

ToolBox - Source for: 107/10790/a.c



/home/toolbox/public_html/solutions/107/10790/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 <stdint.h>
    7 #include <math.h>
    8 #include <stdlib.h>
    9 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /*
   17  *  Author: Isaac Traxler
   18  *    Date: 2021-11-05
   19  * Purpose: fun
   20  * Problem: 10790 - How many points of intersections
   21  */
   22 
   23 /*
   24  * This template reads data until a terminating value is reached.
   25  */
   26 
   27 /* This is a combination/permutation.
   28  * The foemula is:
   29  *
   30  * a * b * (a - 1) * (b - 1)
   31  * -------------------------
   32  *       4
   33  */
   34 
   35 int a;
   36 int b;
   37 
   38 long long int a1;
   39 long long int b1;
   40 
   41 int cnt;
   42 
   43 void init()
   44 {
   45     /* FUNCTION init */
   46     cnt = 1;
   47 } /* FUNCTION init */
   48 
   49 void dump()
   50 {
   51     /* FUNCTION dump */
   52 } /* FUNCTION dump */
   53 
   54 int getInput()
   55 {
   56     /* FUNCTION getInput */
   57     int dataReadFlag;
   58 
   59     scanf(" %d %d ", &a, &b);
   60     dataReadFlag = (0 != a) || (0 != b);
   61     return (dataReadFlag);
   62 } /* FUNCTION getInput */
   63 
   64 void process()
   65 {
   66     /* FUNCTION process */
   67 
   68     if ((1 == a) || (1 == b))
   69         {
   70             printf("Case %d: 0\n", cnt);
   71         }
   72     else
   73         {
   74             /* compute it */
   75             /* either a or a-1 must be even, therefor we can divide by 2 */
   76             a1 = ((a -1) * a ) / 2;
   77             b1 = ((b -1) * b ) / 2;
   78             a1 = a1 * b1;
   79             printf("Case %d: %lld\n", cnt, a1);
   80         } /* compute it */
   81     cnt++;
   82 } /* FUNCTION process */
   83 
   84 int main()
   85 {
   86     /* main */
   87     int moreToDo;
   88 
   89     init();
   90     moreToDo = getInput();
   91     while (moreToDo)
   92         {
   93             /* while */
   94             process();
   95             moreToDo = getInput();
   96         } /* while */
   97 
   98     return EXIT_SUCCESS;
   99 } /* main */
  100