Computer Programming Contest Preparation

ToolBox - Source for: 4/476/a.c



/home/toolbox/public_html/solutions/4/476/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 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /*
   16  *  Author: Isaac Traxler
   17  *    Date: 2015-03-25
   18  * Purpose:
   19  * Problem: 476
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 #define MAX_RECT 12
   27 double rect[MAX_RECT][4];
   28 /* [0] upper left x
   29    [1] upper left y
   30    [2] lower right x
   31    [3] lower right y */
   32 int rectCnt;
   33 double x;
   34 double y;
   35 int pointCnt = 0;
   36 
   37 void init()
   38 {
   39     /* FUNCTION init */
   40     char ch;
   41 
   42     rectCnt = 0;
   43     scanf("%c ", &ch);
   44     while ('*' != ch)
   45         {
   46             /* while */
   47             scanf(" %lf %lf %lf %lf ", &rect[rectCnt][0], &rect[rectCnt][1], &rect[rectCnt][2], &rect[rectCnt][3]);
   48             DEBUG printf("%c: %lf %lf %lf %lf\n", ch, rect[rectCnt][0], rect[rectCnt][1], rect[rectCnt][2], rect[rectCnt][3]);
   49             rectCnt++;
   50             scanf("%c ", &ch);
   51         } /* while */
   52 } /* FUNCTION init */
   53 
   54 void dump()
   55 {
   56     /* FUNCTION dump */
   57 } /* FUNCTION dump */
   58 
   59 int getInput()
   60 {
   61     /* FUNCTION getInput */
   62     int dataReadFlag;
   63 
   64     scanf(" %lf %lf ", &x, &y);
   65     DEBUG printf(" %lf %lf\n", x, y);
   66     dataReadFlag = (x != 9999.9) || (y != 9999.9);
   67     pointCnt++;
   68     return (dataReadFlag);
   69 } /* FUNCTION getInput */
   70 
   71 int check(double x, double y, double r[])
   72 {
   73     /* FUNCTION check */
   74     return (x>r[0]) && (x<r[2]) && (y<r[1]) && (y>r[3]);
   75 } /* FUNCTION check */
   76 
   77 void process()
   78 {
   79     /* FUNCTION process */
   80     int i;
   81     int found = FALSE;
   82 
   83     for (i=0; i<rectCnt; i++)
   84         {
   85             /* for */
   86             if (check(x, y, rect[i]))
   87                 {
   88                     /* contained */
   89                     printf("Point %d is contained in figure %d\n", pointCnt, i+1);
   90                     found = TRUE;
   91                 } /* contained */
   92         } /* for */
   93     if (! found)
   94         {
   95             /* not found */
   96             printf("Point %d is not contained in any figure\n", pointCnt);
   97         } /* not found */
   98 } /* FUNCTION process */
   99 
  100 int main()
  101 {
  102     /* main */
  103     int moreToDo;
  104 
  105     init();
  106     moreToDo = getInput();
  107     while (moreToDo)
  108         {
  109             /* while */
  110             process();
  111             moreToDo = getInput();
  112         } /* while */
  113 
  114     return EXIT_SUCCESS;
  115 } /* main */
  116