Computer Programming Contest Preparation

ToolBox - Source for: 4/414/a.c



/home/toolbox/public_html/solutions/4/414/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 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /*
   16  *  Author: Isaac Traxler
   17  *    Date: 2015-03-24
   18  * Purpose:
   19  * Problem: 414
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 #define MAX_LENGTH 257
   27 #define MAX_LINES 50
   28 
   29 int rows;
   30 char line[MAX_LENGTH];
   31 int blanks[MAX_LINES];
   32 int mn;
   33 
   34 
   35 
   36 void init()
   37 {
   38     /* FUNCTION init */
   39 } /* FUNCTION init */
   40 
   41 void dump()
   42 {
   43     /* FUNCTION dump */
   44 } /* FUNCTION dump */
   45 
   46 int getInput()
   47 {
   48     /* FUNCTION getInput */
   49     int dataReadFlag = TRUE;
   50     int i;
   51     int j;
   52 
   53     scanf(" %d ", &rows);
   54     if (0 < rows)
   55         {
   56             /* data to be processed */
   57             mn = MAX_LENGTH;
   58             for (i=0; i<rows; i++)
   59                 {
   60                     /* for */
   61                     fgets(line, sizeof(line), stdin);
   62                     line[strlen(line)-1] = 0;
   63                     DEBUG printf("%d [%s]\n", strlen(line),line);
   64                     blanks[i] = 0;
   65                     for (j=0; strlen(line)>j; j++)
   66                         {
   67                             /* for */
   68                             if (' ' == line[j])
   69                                 {
   70                                     DEBUG printf("*");
   71                                     blanks[i] = blanks[i] + 1;
   72                                 }
   73                         } /* for */
   74                     if (mn > blanks[i])
   75                         {
   76                             mn = blanks[i];
   77                         }
   78                     DEBUG printf(" %d %d  mnL %d\n", i, blanks[i], mn);
   79                 } /* for */
   80         } /* data to be processed */
   81     else
   82         dataReadFlag = FALSE;
   83     return (dataReadFlag);
   84 } /* FUNCTION getInput */
   85 
   86 void process()
   87 {
   88     /* FUNCTION process */
   89     int i;
   90     int tot = 0;
   91 
   92     for (i=0; i<rows; i++)
   93         {
   94             /* for */
   95             tot = tot + blanks[i] - mn;
   96         } /* for */
   97     DEBUG printf("min = %d\n", mn);
   98     printf("%d\n", tot);
   99 } /* FUNCTION process */
  100 
  101 int main()
  102 {
  103     /* main */
  104     int moreToDo;
  105 
  106     init();
  107     moreToDo = getInput();
  108     while (moreToDo)
  109         {
  110             /* while */
  111             process();
  112             moreToDo = getInput();
  113         } /* while */
  114 
  115     return EXIT_SUCCESS;
  116 } /* main */
  117