Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/118/11849/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: 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 init()
   33 {
   34     /* FUNCTION init */
   35     int i;
   36 
   37     for (i=1; MAX_CDS>i; i++)
   38         {
   39             /* for each location */
   40             catalog[i] = 0;
   41         } /* for each location */
   42 } /* FUNCTION init */
   43 
   44 void dump()
   45 {
   46     /* FUNCTION dump */
   47 } /* FUNCTION dump */
   48 
   49 int getInput()
   50 {
   51     /* FUNCTION getInput */
   52     int dataReadFlag;
   53 
   54     scanf(" %d %d ", &jackCnt, &jillCnt);
   55     dataReadFlag = ((0 != jackCnt) || (0 != jillCnt));
   56     return (dataReadFlag);
   57 } /* FUNCTION getInput */
   58 
   59 void process()
   60 {
   61     /* FUNCTION process */
   62     int i;
   63     int num;
   64 
   65     for (i=0; jackCnt>i; i++)
   66         {
   67             /* do all of Jack's CDs */
   68             scanf(" %d ", &num);
   69             catalog[num]++;
   70         } /* do all of Jack's CDs */
   71 
   72     for (i=0; jillCnt>i; i++)
   73         {
   74             /* do all of Jill's CDs */
   75             scanf(" %d ", &num);
   76             catalog[num]++;
   77         } /* do all of Jill's CDs */
   78 
   79     num = 0;
   80     for (i=1; MAX_CDS>i; i++)
   81         {
   82             /* for each location */
   83             if ( 2== catalog[i])
   84                 {
   85                     /* found a CD they both have */
   86                     num++;
   87                 } /* found a CD they both have */
   88         } /* for each location */
   89     printf("%d\n", num);
   90 } /* FUNCTION process */
   91 
   92 int main()
   93 {
   94     /* main */
   95     int moreToDo;
   96 
   97     moreToDo = getInput();
   98     while (moreToDo)
   99         {
  100             /* while */
  101             init();
  102             process();
  103             moreToDo = getInput();
  104         } /* while */
  105 
  106     return EXIT_SUCCESS;
  107 } /* main */
  108