Computer Programming Contest Preparation

ToolBox - Source for: 114/11462/a.c



/home/toolbox/public_html/solutions/114/11462/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-15
   18  * Purpose:
   19  * Problem: 11462
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 #define MAX_AGES 101
   27 
   28 int count;
   29 int ages[MAX_AGES];
   30 
   31 void init()
   32 {
   33     /* FUNCTION init */
   34     int i;
   35 
   36     for (i=0; i<MAX_AGES; i++)
   37         {
   38             ages[i] = 0;
   39         }
   40 } /* FUNCTION init */
   41 
   42 void dump()
   43 {
   44     /* FUNCTION dump */
   45 } /* FUNCTION dump */
   46 
   47 int getInput()
   48 {
   49     /* FUNCTION getInput */
   50     int dataReadFlag;
   51     int i;
   52     int tmp;
   53 
   54     scanf(" %d ", &count);
   55 
   56     init();
   57     if (0 == count)
   58         {
   59             /* stop */
   60             dataReadFlag = FALSE;
   61         } /* stop */
   62     else
   63         {
   64             /* load ages */
   65             dataReadFlag = TRUE;
   66             for (i=0; i<count; i++)
   67                 {
   68                     /* for */
   69                     scanf(" %d ", &tmp);
   70                     ages[tmp]++;
   71                 } /* for */
   72         } /* load ages */
   73 
   74     return (dataReadFlag);
   75 } /* FUNCTION getInput */
   76 
   77 void process()
   78 {
   79     /* FUNCTION process */
   80     int i;
   81     int j;
   82     int notFirst = FALSE;
   83 
   84     for (i=0; i<MAX_AGES; i++)
   85         {
   86             /* for */
   87             for (j=0; j<ages[i]; j++)
   88                 {
   89                     /* for j */
   90                     if (notFirst)
   91                         printf(" %d", i);
   92                     else
   93                         {
   94                             /* first time */
   95                             notFirst = TRUE;
   96                             printf("%d", i);
   97                         } /* first time */
   98                 } /* for j */
   99         } /* for */
  100     printf("\n");
  101 } /* FUNCTION process */
  102 
  103 int main()
  104 {
  105     /* main */
  106     int moreToDo;
  107 
  108     moreToDo = getInput();
  109     while (moreToDo)
  110         {
  111             /* while */
  112             process();
  113             moreToDo = getInput();
  114         } /* while */
  115 
  116     return EXIT_SUCCESS;
  117 } /* main */
  118