Computer Programming Contest Preparation

ToolBox - Source for: 2/278/a.c



/home/toolbox/public_html/solutions/2/278/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 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /* fprintf(stderr, "functionName: message", varslist); */
   17 
   18 /*
   19  *  Author: Isaac Traxler
   20  *    Date: 2021-11-05
   21  * Purpose: fun
   22  * Problem: 278 - Chess
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  */
   28 
   29 int numberOfTimes;
   30 
   31 char piece;
   32 int  rows;
   33 int  cols;
   34 int cnt;
   35 
   36 void init()
   37 {
   38     /* FUNCTION init */
   39     scanf("%d ", &numberOfTimes);
   40 } /* FUNCTION init */
   41 
   42 void dump()
   43 {
   44     /* FUNCTION dump */
   45 } /* FUNCTION dump */
   46 
   47 void getInput()
   48 {
   49     /* FUNCTION getInput */
   50     int tmp;
   51     scanf("%c %d %d ", &piece, &rows, &cols);
   52     if (rows > cols)
   53         {
   54             /* swap so rows is always less than or rqual to cols */
   55             tmp = rows;
   56             rows = cols;
   57             cols = tmp;
   58         } /* swap so rows is always less than or rqual to cols */
   59 } /* FUNCTION getInput */
   60 
   61 void process()
   62 {
   63     /* FUNCTION process */
   64     switch (piece)
   65         {
   66         /* switch */
   67         case 'r': /* rook */
   68             cnt = rows;
   69             break;
   70         case 'k': /* knight */
   71             cnt = ((rows * cols) + 1) / 2;
   72             break;
   73         case 'Q': /* queen */
   74             cnt = rows;
   75             break;
   76         case 'K': /* king */
   77             cnt = ((cols + 1) / 2) * ((rows + 1) / 2);
   78             break;
   79         } /* switch */
   80     printf("%d\n", cnt);
   81 } /* FUNCTION process */
   82 
   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