Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/4/484/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 #define MAX_LINE 257
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2016-03-29
   20  * Purpose: fun
   21  * Problem: 484 - The Department of Redundancy Department
   22  */
   23 
   24 /*
   25  * This template reads lines of data at a time until end of file.
   26  */
   27 
   28 #define MAX_NUMS 100000
   29 
   30 int num;
   31 int tbl[MAX_NUMS][2];
   32 int cnt = 0;
   33 
   34 void init()
   35 {
   36     /* FUNCTION init */
   37 } /* FUNCTION init */
   38 
   39 void dump()
   40 {
   41     /* FUNCTION dump */
   42     int i;
   43 
   44     for (i=0; i<cnt; i++)
   45         {
   46             /* for */
   47             printf("%d %d\n", tbl[i][0], tbl[i][1]);
   48         } /* for */
   49 } /* FUNCTION dump */
   50 
   51 int getInput()
   52 {
   53     /* FUNCTION getInput */
   54     int dataReadFlag;
   55 
   56     dataReadFlag = (1 == scanf(" %d ", &num));
   57 
   58     return (dataReadFlag);
   59 } /* FUNCTION getInput */
   60 
   61 void process()
   62 {
   63     /* FUNCTION process */
   64     int i = 0;
   65     int fnd = -1;
   66 
   67     /* see if num is in list */
   68     while (i < cnt)
   69         {
   70             /* while */
   71             if (num == tbl[i][0])
   72                 {
   73                     /* found it */
   74                     tbl[i][1] = tbl[i][1] + 1;;
   75                     fnd = i;
   76                     i = cnt;
   77                 } /* found it */
   78             i++;
   79         } /* while */
   80     if (-1 == fnd)
   81         {
   82             /* was not found -- need to insert */
   83             tbl[cnt][0] = num;
   84             tbl[cnt][1] = 1;
   85             cnt++;
   86         } /* was not found -- need to insert */
   87 } /* FUNCTION process */
   88 
   89 int main()
   90 {
   91     /* main */
   92     int moreToDo;
   93 
   94     init();
   95     moreToDo = getInput();
   96     while (moreToDo)
   97         {
   98             /* while */
   99             process();
  100             moreToDo = getInput();
  101         } /* while */
  102     dump();
  103     return EXIT_SUCCESS;
  104 } /* main */
  105