Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/114/11462/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 <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_PEOPLE 2000001
   27 
   28 int count;
   29 unsigned char ages[MAX_PEOPLE];
   30 
   31 void init()
   32 {
   33     /* FUNCTION init */
   34 } /* FUNCTION init */
   35 
   36 void dump()
   37 {
   38     /* FUNCTION dump */
   39 } /* FUNCTION dump */
   40 
   41 int getInput()
   42 {
   43     /* FUNCTION getInput */
   44     int dataReadFlag;
   45     int i;
   46     int tmp;
   47 
   48     scanf(" %d ", &count);
   49 
   50     if (0 == count)
   51         {
   52             /* stop */
   53             dataReadFlag = 0;
   54         } /* stop */
   55     else
   56         {
   57             /* load ages */
   58             for (i=0; i<count; i++)
   59                 {
   60                     /* for */
   61                     scanf(" %d ", &tmp);
   62                     ages[i] = tmp;
   63                 } /* for */
   64         } /* load ages */
   65 
   66     return (dataReadFlag);
   67 } /* FUNCTION getInput */
   68 
   69 int intcomp(const unsigned char * a, const unsigned char * b)
   70 {
   71     /* FUNCTION intcomp */
   72     int toReturn = 0;
   73     if (*a < *b)
   74         {
   75             toReturn = -1;
   76         }
   77     else if (*a > *b)
   78         {
   79             toReturn = 1;
   80         }
   81     return toReturn;
   82 } /* FUNCTION intcomp */
   83 
   84 void process()
   85 {
   86     /* FUNCTION process */
   87     int i;
   88 
   89     qsort(ages, count, sizeof(unsigned char), intcomp);
   90     printf("%d", ages[0]);
   91     for (i=1; i<count; i++)
   92         {
   93             printf(" %d", ages[i]);
   94         }
   95     printf("\n");
   96 } /* FUNCTION process */
   97 
   98 int main()
   99 {
  100     /* main */
  101     int moreToDo;
  102 
  103     init();
  104     moreToDo = getInput();
  105     while (moreToDo)
  106         {
  107             /* while */
  108             process();
  109             moreToDo = getInput();
  110         } /* while */
  111 
  112     return EXIT_SUCCESS;
  113 } /* main */
  114