Computer Programming Contest Preparation

ToolBox - Source for: 106/10611/wrong.c



/home/toolbox/public_html/solutions/106/10611/wrong.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: 2017-08-28
   20  * Purpose: fun
   21  * Problem: 10611 - The Playboy Chimp
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define MAX_FEMALES 50002
   29 #define MISSING 0
   30 #define FOUND 1
   31 
   32 int numberOfTimes;
   33 int numberOfFemales;
   34 int females[MAX_FEMALES];
   35 int tallest;
   36 int shortest;
   37 int luchu;
   38 
   39 void init()
   40 {
   41     /* FUNCTION init */
   42     int i;
   43     int tmp;
   44 
   45     /* empty out list */
   46     for (i=0; MAX_FEMALES>i; i++)
   47         {
   48             females[i] = MISSING;
   49         }
   50 
   51     scanf(" %d ", &numberOfFemales);
   52     /* do first one so we can find shortest */
   53     scanf(" %d ", &shortest);
   54     females[shortest] = FOUND;
   55     /* mark heights that are found */
   56     for (i=1; numberOfFemales > i; i++)
   57         {
   58             /* for */
   59             scanf(" %d ", &tmp);
   60             females[tmp] = FOUND;
   61         } /* for */
   62     tallest = tmp;
   63 
   64     /* get number of heights luchu might be */
   65     scanf(" %d ", &numberOfTimes);
   66 
   67     DEBUG printf("shortest: %d     tallest: %d\n", shortest, tallest);
   68 } /* FUNCTION init */
   69 
   70 void dump()
   71 {
   72     /* FUNCTION dump */
   73 } /* FUNCTION dump */
   74 
   75 void getInput()
   76 {
   77     /* FUNCTION getInput */
   78     scanf(" %d ", &luchu);
   79 } /* FUNCTION getInput */
   80 
   81 void process()
   82 {
   83     /* FUNCTION process */
   84     int i;
   85 
   86     for (i=(luchu-1); (shortest <= i) && (MISSING == females[i]); i--) {}
   87     if (0<i)
   88         {
   89             /* shorter girl found */
   90             printf("%d ", i);
   91         } /* shorter girl found */
   92     else
   93         {
   94             /* no girls shorter than luchu */
   95             printf("X ");
   96         } /* no girls shorter than luchu */
   97 
   98     for (i=(luchu+1); (tallest >= i) && (MISSING == females[i]); i++)
   99         {
  100             DEBUG printf("trying %d\n", i);
  101         }
  102     if (tallest >= i)
  103         {
  104             /* girl found taller than luchu */
  105             printf("%d\n", i);
  106         } /* girl found taller than luchu */
  107     else
  108         {
  109             /* no girls taller */
  110             printf("X\n");
  111         } /* no girls taller */
  112 
  113 } /* FUNCTION process */
  114 
  115 int main()
  116 {
  117     /* main */
  118     int i;
  119 
  120     init();
  121     for (i=0; numberOfTimes>i; i++)
  122         {
  123             /* while */
  124             getInput();
  125             process();
  126         } /* while */
  127 
  128     return EXIT_SUCCESS;
  129 } /* main */
  130 
  131