Computer Programming Contest Preparation

ToolBox - Source for: 101/10141/a.c



/home/toolbox/public_html/solutions/101/10141/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 <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-04-15
   19  * Purpose: fun
   20  * Problem: 10141 - Request for Proposal
   21  */
   22 
   23 /*
   24  * This template reads data until a terminating value is reached.
   25  */
   26 
   27 /* started assuming that reqwould need to be searched. Actually it is all irrelevant:
   28  * for each met requirement, the name of the requirement, each on a separate line. All
   29  * requirements are from the RFP requirement list, and no requirements are duplicated.
   30  *
   31  * So the requirement count is all that is needed
   32  */
   33 
   34 #define MAX_RFPS 1004
   35 #define MAX_LINE 84
   36 
   37 int numReq;    /* number of requirements for RFP */
   38 int numBids;   /* number of bids */
   39 char bids[MAX_RFPS][MAX_LINE]; /* names of all bids */
   40 double cost[MAX_RFPS];         /* cost of each bid */
   41 int met[MAX_RFPS];             /* number of requirements met */
   42 char line[MAX_LINE];
   43 int printCnt;
   44 int winner;
   45 
   46 void init()
   47 {
   48     /* FUNCTION init */
   49     printCnt = 0;
   50 } /* FUNCTION init */
   51 
   52 void dump()
   53 {
   54     /* FUNCTION dump */
   55     int i;
   56 
   57     winner = 0;
   58     printf("RFP #%d\n", printCnt);
   59     for (i=0; i<numBids; i++)
   60         {
   61             /* for each bid */
   62         } /* for each bid */
   63 
   64 } /* FUNCTION dump */
   65 
   66 int getInput()
   67 {
   68     /* FUNCTION getInput */
   69     int dataReadFlag;
   70     int i;
   71     int j;
   72     int tmpCnt;
   73     double tmp;
   74 
   75     scanf(" %d %d ", &numReq, &numBids);
   76     dataReadFlag = (0 != numReq) || (0 != numBids);
   77     if (dataReadFlag)
   78         {
   79             /* actually get data */
   80             winner = 0;
   81             DEBUG printf("(numReq = %d)  (numBids = %d)\n", numReq, numBids);
   82             /* blow past all requirements becasue we never use them */
   83             for (i=0; i<numReq; i++)
   84                 {
   85                     /* get each requirement */
   86                     fgets(line, MAX_LINE, stdin);
   87                     DEBUG printf("requirement: %s", line);
   88                 } /* get each requirement */
   89             /* get bid data */
   90             for (i=0; i<numBids; i++)
   91                 {
   92                     /* get each bid */
   93                     fgets(bids[i], MAX_LINE, stdin);
   94                     bids[i][strlen(bids[i])-1] = 0; /* remove newline */
   95                     scanf(" %lf %d ", &cost[i], &met[i]);
   96                     DEBUG printf("bid: [%s] (cost: %lf) (met: %d)\n", bids[i], cost[i], met[i]);
   97                     /* blow past unneeded names of the options */
   98                     for (j=0; j<met[i]; j++)
   99                         {
  100                             /* for each option */
  101                             fgets(line, MAX_LINE, stdin);
  102                         } /* for each option */
  103                     if (met[i] > met[winner])
  104                         {
  105                             /* we have a new winner */
  106                             winner = i;
  107                         } /* we have a new winner */
  108                     else if (met[i] == met[winner])
  109                         {
  110                             /* potentia;l; new winner */
  111                             if (cost[i] < cost[winner])
  112                                 {
  113                                     /* new winning bid */
  114                                     winner = i;
  115                                 } /* new winning bid */
  116                         } /* potentia;l; new winner */
  117                 } /* get each bid */
  118         } /* actually get data */
  119     return (dataReadFlag);
  120 } /* FUNCTION getInput */
  121 
  122 void process()
  123 {
  124     /* FUNCTION process */
  125     printCnt++;
  126     if (1 < printCnt)
  127         {
  128             printf("\n");
  129         }
  130     printf("RFP #%d\n", printCnt);
  131     printf("%s\n", bids[winner]);
  132 } /* FUNCTION process */
  133 
  134 int main()
  135 {
  136     /* main */
  137     int moreToDo;
  138 
  139     init();
  140     moreToDo = getInput();
  141     while (moreToDo)
  142         {
  143             /* while */
  144             process();
  145             moreToDo = getInput();
  146         } /* while */
  147 
  148     return EXIT_SUCCESS;
  149 } /* main */
  150