Computer Programming Contest Preparation

ToolBox - Source for: 125/12583/a.c



/home/toolbox/public_html/solutions/125/12583/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 <stdlib.h>
    7 #include <math.h>
    8 #include <stdint.h>
    9 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /* fprintf(stderr, "functionName: message", varslist); */
   17 
   18 /*
   19  *  Author: Isaac Traxler
   20  *    Date: 2021-12-16
   21  * Purpose: fun
   22  * Problem: 12583 - Memory Overflow
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  */
   28 
   29 #define MAX_LINE 505
   30 #define MAX_PEOPLE 26
   31 #define NEVER_MET -9999999
   32 
   33 int numberOfTimes;
   34 int peopleCnt;
   35 int memory;
   36 char line[MAX_LINE];
   37 int people[MAX_PEOPLE];
   38 
   39 void init()
   40 {
   41     /* FUNCTION init */
   42     scanf("%d ", &numberOfTimes);
   43 } /* FUNCTION init */
   44 
   45 void dump()
   46 {
   47     /* FUNCTION dump */
   48 } /* FUNCTION dump */
   49 
   50 void getInput()
   51 {
   52     /* FUNCTION getInput */
   53     scanf(" %d %d %s ", &peopleCnt, &memory, line);
   54 } /* FUNCTION getInput */
   55 
   56 void process()
   57 {
   58     /* FUNCTION process */
   59     int i;
   60     int tot = 0;
   61     int tmp;
   62 
   63     for (i=0; MAX_PEOPLE>i; i++)
   64         {
   65             people[i] = NEVER_MET;
   66         }
   67 
   68     for (i=0; peopleCnt>i; i++)
   69         {
   70             /* for each person met */
   71             tmp = line[i] - 'A';
   72             DEBUG printf("%d: line[%d] %c  tmp: %d  memory: %d  people[%d] %d  tot: %d\n", i, i, line[i], tmp, memory, tmp, people[tmp], tot);
   73             if ((i - memory) < people[tmp])
   74                 {
   75                     /* met someone he knew */
   76                     tot++;
   77                 } /* met someone he knew */
   78             people[tmp] = i + 1;
   79         } /* for each person met */
   80     printf("%d\n", tot);
   81 } /* FUNCTION process */
   82 
   83 int main()
   84 {
   85     /* main */
   86     int i;
   87 
   88     init();
   89     for (i=1; i<=numberOfTimes; i++)
   90         {
   91             /* while */
   92             getInput();
   93             printf("Case %d: ", i);
   94             process();
   95         } /* while */
   96 
   97     return EXIT_SUCCESS;
   98 } /* main */
   99 
  100