Computer Programming Contest Preparation

ToolBox - Source for: 118/11849/c.c



/home/toolbox/public_html/solutions/118/11849/c.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: 2018-08-28
   18  * Purpose: fun
   19  * Problem: 11849
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 #define MAX_CDS 1000000005
   27 
   28 int jackCnt;
   29 int jillCnt;
   30 unsigned char catalog[MAX_CDS];
   31 
   32 void dump()
   33 {
   34     /* FUNCTION dump */
   35 } /* FUNCTION dump */
   36 
   37 int getInput()
   38 {
   39     /* FUNCTION getInput */
   40     int dataReadFlag;
   41 
   42     scanf(" %d %d ", &jackCnt, &jillCnt);
   43     dataReadFlag = ((0 != jackCnt) || (0 != jillCnt));
   44     if (dataReadFlag)
   45         {
   46             memset(catalog, sizeof catalog, 0);
   47         }
   48     return (dataReadFlag);
   49 } /* FUNCTION getInput */
   50 
   51 void process()
   52 {
   53     /* FUNCTION process */
   54     int i;
   55     int num;
   56 
   57     for (i=0; jackCnt>i; i++)
   58         {
   59             /* do all of Jack's CDs */
   60             scanf(" %d ", &num);
   61             catalog[num]++;
   62         } /* do all of Jack's CDs */
   63 
   64     for (i=0; jillCnt>i; i++)
   65         {
   66             /* do all of Jill's CDs */
   67             scanf(" %d ", &num);
   68             catalog[num]++;
   69         } /* do all of Jill's CDs */
   70 
   71     num = 0;
   72     for (i=1; MAX_CDS>i; i++)
   73         {
   74             /* for each location */
   75             if ( 2== catalog[i])
   76                 {
   77                     /* found a CD they both have */
   78                     num++;
   79                 } /* found a CD they both have */
   80         } /* for each location */
   81     printf("%d\n", num);
   82 } /* FUNCTION process */
   83 
   84 int main()
   85 {
   86     /* main */
   87     int moreToDo;
   88 
   89     moreToDo = getInput();
   90     while (moreToDo)
   91         {
   92             /* while */
   93             process();
   94             moreToDo = getInput();
   95         } /* while */
   96 
   97     return EXIT_SUCCESS;
   98 } /* main */
   99