Computer Programming Contest Preparation

ToolBox - Source for: 12/1237/a.c



/home/toolbox/public_html/solutions/12/1237/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 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /* fprintf(stderr, "functionName: message", varslist); */
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2020-03-31
   20  * Purpose: fun
   21  * Problem: 1237 - expert enough
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define MAX_CNT 10005
   29 
   30 
   31 int numberOfTimes;
   32 char names[MAX_CNT][22];
   33 int low[MAX_CNT];
   34 int high[MAX_CNT];
   35 int idx;
   36 int match;
   37 int cars;
   38 int queries;
   39 
   40 void init()
   41 {
   42     /* FUNCTION init */
   43     scanf("%d ", &numberOfTimes);
   44 } /* FUNCTION init */
   45 
   46 void dump()
   47 {
   48     /* FUNCTION dump */
   49 } /* FUNCTION dump */
   50 
   51 void getInput()
   52 {
   53     /* FUNCTION getInput */
   54     int i;
   55 
   56     scanf(" %d ", &cars);
   57     for (i=0; i<cars; i++)
   58         {
   59             /* get each car record */
   60             scanf(" %s %d %d ", names[i], &low[i], &high[i]);
   61         } /* get each car record */
   62     scanf(" %d ", &queries);
   63 } /* FUNCTION getInput */
   64 
   65 void process()
   66 {
   67     /* FUNCTION process */
   68     int i;
   69     int j;
   70     int amount;
   71 
   72     for (i=0; i<queries; i++)
   73         {
   74             /* do a query */
   75             scanf(" %d ", &amount);
   76             match = 0;
   77             for (j=0; (j<cars) && (match < 2); j++)
   78                 {
   79                     /* check each car */
   80                     if ((amount >= low[j]) && (amount <= high[j]))
   81                         {
   82                             /* found a match */
   83                             idx = j;
   84                             match ++;
   85                         } /* found a match */
   86                 } /* check each car */
   87             if (1 == match)
   88                 {
   89                     /* found a winner */
   90                     printf("%s\n", names[idx]);
   91                 } /* found a winner */
   92             else
   93                 {
   94                     /* no winner */
   95                     printf("UNDETERMINED\n");
   96                 } /* no winner */
   97         } /* do a query */
   98 } /* FUNCTION process */
   99 
  100 int main()
  101 {
  102     /* main */
  103     int i;
  104 
  105     init();
  106     for (i=0; i<numberOfTimes; i++)
  107         {
  108             /* while */
  109             if (0 <i)
  110                 {
  111                     printf("\n");
  112                 }
  113             getInput();
  114             process();
  115         } /* while */
  116 
  117     return EXIT_SUCCESS;
  118 } /* main */
  119 
  120