Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/2/278/b.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 + 1) / 2) * cols;
   72             break;
   73         case 'Q': /* queen */
   74             if ((4 == rows) && (4 == cols))
   75                 {
   76                     cnt = 3;
   77                 }
   78             else
   79                 cnt = rows;
   80             break;
   81         case 'K': /* king */
   82             cnt = ((cols + 1) / 2) * ((rows + 1) / 2);
   83             break;
   84         } /* switch */
   85     printf("%d\n", cnt);
   86 } /* FUNCTION process */
   87 
   88 
   89 int main()
   90 {
   91     /* main */
   92     int i;
   93 
   94     init();
   95     for (i=0; i<numberOfTimes; i++)
   96         {
   97             /* while */
   98             getInput();
   99             process();
  100         } /* while */
  101 
  102     return EXIT_SUCCESS;
  103 } /* main */
  104 
  105