Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/106/10611/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: 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 
   30 int numberOfTimes;
   31 int numberOfFemales;
   32 int females[MAX_FEMALES];
   33 int luchu;
   34 
   35 void init()
   36 {
   37     /* FUNCTION init */
   38     int i;
   39     int tmp;
   40 
   41     scanf(" %d ", &numberOfFemales);
   42     /* mark heights that are found */
   43     for (i=0; numberOfFemales > i; i++)
   44         {
   45             /* for */
   46             scanf(" %d ", &females[i]);
   47         } /* for */
   48 
   49     /* get number of heights luchu might be */
   50     scanf(" %d ", &numberOfTimes);
   51 } /* FUNCTION init */
   52 
   53 void dump()
   54 {
   55     /* FUNCTION dump */
   56 } /* FUNCTION dump */
   57 
   58 void getInput()
   59 {
   60     /* FUNCTION getInput */
   61     scanf(" %d ", &luchu);
   62 } /* FUNCTION getInput */
   63 
   64 void process()
   65 {
   66     /* FUNCTION process */
   67     int i;
   68     int found;
   69 
   70     /* speed would be reduced if a binary search was used */
   71 
   72     /* look for first girl not shorter than lucha's height */
   73     for (i=0; ((luchu > females[i]) && (numberOfFemales > i)); i++) { }
   74     if (0 < i)
   75         {
   76             /* shorter girl found */
   77             printf("%d ", females[i - 1]); /* print out previous girl */
   78         } /* shorter girl found */
   79     else
   80         {
   81             /* no girls shorter than luchu */
   82             printf("X ");
   83         } /* no girls shorter than luchu */
   84 
   85     while ((numberOfFemales > i) && (luchu >= females[i]) )
   86         {
   87             /* keep going -- same height as lucha */
   88             i++;
   89         } /* keep going -- same height as lucha */
   90     if (numberOfFemales > i)
   91         {
   92             /* girl found taller than luchu */
   93             printf("%d\n", females[i]);
   94         } /* girl found taller than luchu */
   95     else
   96         {
   97             /* no girls taller */
   98             printf("X\n");
   99         } /* no girls taller */
  100 
  101 } /* FUNCTION process */
  102 
  103 int main()
  104 {
  105     /* main */
  106     int i;
  107 
  108     init();
  109     for (i=0; numberOfTimes>i; i++)
  110         {
  111             /* while */
  112             getInput();
  113             process();
  114         } /* while */
  115 
  116     return EXIT_SUCCESS;
  117 } /* main */
  118 
  119