Computer Programming Contest Preparation

ToolBox - Source for: 126/12626/b.c



/home/toolbox/public_html/solutions/126/12626/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 
   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: 2015-10-06
   20  * Purpose: fun
   21  * Problem: 12626 - I Love Pizza
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define MAX_SIZE 625
   29 #define M 'M'
   30 #define A 'A'
   31 #define R 'R'
   32 #define G 'G'
   33 #define I 'I'
   34 #define T 'T'
   35 
   36 #define mn(x, y) (x < y ? x : y)
   37 
   38 int numberOfTimes;
   39 char buff[MAX_SIZE];
   40 int letters[256];
   41 
   42 void init()
   43 {
   44     /* FUNCTION init */
   45     scanf("%d ", &numberOfTimes);
   46 } /* FUNCTION init */
   47 
   48 void dump()
   49 {
   50     /* FUNCTION dump */
   51 } /* FUNCTION dump */
   52 
   53 void getInput()
   54 {
   55     /* FUNCTION getInput */
   56     int i;
   57 
   58     for (i=0; i<256; i++)
   59         {
   60             letters[i] = 0;
   61         }
   62     scanf(" %s ", buff);
   63 } /* FUNCTION getInput */
   64 
   65 void process()
   66 {
   67     /* FUNCTION process */
   68     int i;
   69     int min;
   70     int tmp;
   71 
   72     for (i=0; i<strlen(buff); i++)
   73         {
   74             /* for */
   75             letters[buff[i]]++;
   76         } /* for */
   77     tmp = mn(
   78               mn(
   79                   mn(letters[M], (letters[A]/3)),
   80                   letters[I]),
   81               mn(
   82                   mn((letters[R] >> 1), letters[G]),
   83                   letters[T]));
   84     printf("%d\n", tmp);
   85 } /* FUNCTION process */
   86 
   87 int main()
   88 {
   89     /* main */
   90     int i;
   91 
   92     init();
   93     for (i=0; i<numberOfTimes; i++)
   94         {
   95             /* while */
   96             getInput();
   97             process();
   98         } /* while */
   99 
  100     return EXIT_SUCCESS;
  101 } /* main */
  102 
  103