Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/126/12626/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 
   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 int numberOfTimes;
   37 char buff[MAX_SIZE];
   38 int letters[256];
   39 
   40 void init()
   41 {
   42     /* FUNCTION init */
   43     scanf("%d ", &numberOfTimes);
   44 } /* FUNCTION init */
   45 
   46 void dump()
   47 {
   48     /* FUNCTION dump */
   49 } /* FUNCTION dump */
   50 
   51 void getInput()
   52 {
   53     /* FUNCTION getInput */
   54     int i;
   55 
   56     for (i=0; i<256; i++)
   57         {
   58             letters[i] = 0;
   59         }
   60     scanf(" %s ", buff);
   61 } /* FUNCTION getInput */
   62 
   63 void process()
   64 {
   65     /* FUNCTION process */
   66     int i;
   67     int min;
   68     int tmp;
   69 
   70     for (i=0; i<strlen(buff); i++)
   71         {
   72             letters[buff[i]]++;
   73         }
   74     min = letters[M];
   75     tmp = letters[A] / 3;
   76     if (tmp < min)
   77         {
   78             min = tmp;
   79         }
   80     tmp = letters[R] / 2;
   81     if (tmp < min)
   82         {
   83             min = tmp;
   84         }
   85     tmp = letters[G];
   86     if (tmp < min)
   87         {
   88             min = tmp;
   89         }
   90     tmp = letters[I];
   91     if (tmp < min)
   92         {
   93             min = tmp;
   94         }
   95     tmp = letters[T];
   96     if (tmp < min)
   97         {
   98             min = tmp;
   99         }
  100     printf("%d\n", min);
  101 } /* FUNCTION process */
  102 
  103 int main()
  104 {
  105     /* main */
  106     int i;
  107 
  108     init();
  109     for (i=0; i<numberOfTimes; i++)
  110         {
  111             /* while */
  112             getInput();
  113             process();
  114         } /* while */
  115 
  116     return EXIT_SUCCESS;
  117 } /* main */
  118 
  119