Computer Programming Contest Preparation

ToolBox - Source for: naq/2025/c.c



/home/toolbox/public_html/solutions/naq/2025/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 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /*
   17  *  Author: Isaac Traxler
   18  *    Date: 2025-10-11
   19  * Purpose: fun
   20  * Problem: naq-c
   21  */
   22 
   23 /*
   24  * This template reads data until a terminating value is reached.
   25  */
   26 
   27 #define MAXD 52
   28 
   29 int d[MAXD];
   30 int n;
   31 int k;
   32 int u;
   33 
   34 void init()
   35 {
   36     /* FUNCTION init */
   37     int i;
   38 
   39     for (i=0; i<MAXD; i++)
   40         {
   41             d[i] = 0;
   42         }
   43 } /* FUNCTION init */
   44 
   45 void dump()
   46 {
   47     /* FUNCTION dump */
   48 } /* FUNCTION dump */
   49 
   50 void getInput()
   51 {
   52     /* FUNCTION getInput */
   53     int i;
   54     int t;
   55 
   56     scanf(" %d %d ", &n, &k);
   57     for (i=0; i<n; i++)
   58         {
   59             /* read each diff */
   60             scanf(" %d ", &t);
   61             d[t] = 1;
   62         } /* read each diff */
   63 } /* FUNCTION getInput */
   64 
   65 void process()
   66 {
   67     /* FUNCTION process */
   68     int i;
   69 
   70     u = 0;
   71 
   72     for (i=0; i<MAXD; i++)
   73         {
   74             /* for i */
   75             u = u + d[i];
   76         } /* for i */
   77     if (u > k)
   78         {
   79             u = k;
   80         }
   81     printf("%d\n", u);
   82 
   83 } /* FUNCTION process */
   84 
   85 int main()
   86 {
   87     /* main */
   88     int moreToDo;
   89 
   90     init();
   91     getInput();
   92     process();
   93 
   94     return EXIT_SUCCESS;
   95 } /* main */
   96