Computer Programming Contest Preparation

ToolBox - Source for: 1/191/a.c



/home/toolbox/public_html/solutions/1/191/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: 2019-01-23
   20  * Purpose: fun
   21  * Problem: 191 - Intersection
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define DIFFERENT -1
   29 #define SAME 1
   30 
   31 typedef struct POINT_STRUCT
   32 {
   33     int x;
   34     int y;
   35 } POINT_STRUCT;
   36 
   37 
   38 int numberOfTimes;
   39 POINT_STRUCT l1;
   40 POINT_STRUCT l2;
   41 POINT_STRUCT r1;
   42 POINT_STRUCT r2;
   43 POINT_STRUCT r3;
   44 POINT_STRUCT r4;
   45 /* rectangle is
   46  *
   47  * r1  r2
   48  * r4  r3
   49  */
   50 
   51 int min(int a, int b)
   52 {
   53     /* FUNCTION min */
   54     return a < b ? a : b;
   55 } /* FUNCTION min */
   56 
   57 int max(int a, int b)
   58 {
   59     /* FUNCTION max */
   60     return a > b ? a : b;
   61 } /* FUNCTION max */
   62 
   63 void init()
   64 {
   65     /* FUNCTION init */
   66     scanf("%d ", &numberOfTimes);
   67 } /* FUNCTION init */
   68 
   69 void dump()
   70 {
   71     /* FUNCTION dump */
   72 } /* FUNCTION dump */
   73 
   74 void getInput()
   75 {
   76     /* FUNCTION getInput */
   77     scanf(" %d %d %d %d %d %d %d %d ", &l1.x, &l1.y, &l2.x, &l2.y, &r1.x, &r1.y, &r3.x, &r3.y);
   78     r2.x = r3.x;
   79     r2.y = r1.y;
   80     r4.x = r1.x;
   81     r4.y = r3.y;
   82 } /* FUNCTION getInput */
   83 
   84 int direction(POINT_STRUCT a, POINT_STRUCT b, POINT_STRUCT c)
   85 {
   86     /* FUNCTION direction */
   87     /* vector abc can be:
   88      * -1 counterclockwise
   89      *  0 linear
   90      *  1 clockwise
   91      */
   92     int ret;
   93 
   94     ret = (b.y - a.y) * (c.x - b.x) - (b.x - a.x) * (c.y - b.y);
   95     ret = ret / abs(ret);
   96     return ret;
   97 } /* FUNCTION direction */
   98 
   99 int intersect(int a, int b)
  100 {
  101     /* FUNCTION intersect */
  102     int ret;
  103 
  104     if ((0 != a) && (0 != b))
  105         {
  106             /* nothing colinear */
  107             ret = (a != b);
  108         } /* nothing colinear */
  109     return ret;
  110 } /* FUNCTION intersect */
  111 
  112 int inLineSegment(POINT_STRUCT a, POINT_STRUCT b, POINT_STRUCT c)
  113 {
  114     /* FUNCTION inLineSegment */
  115 
  116 } /* FUNCTION inLineSegment */
  117 
  118 void process()
  119 {
  120     /* FUNCTION process */
  121     int d1;
  122     int d2;
  123     int d3;
  124     int d4;
  125 
  126     d1 = direction(l1, l2, r1);
  127     if (0 == d1)
  128         {
  129             /* colinear */
  130             intersected = ((l1.x
  131         } /* colinear */
  132                    printf("r1 - %d\n", d1);
  133                   d2 = direction(l1, l2, r2);
  134                   printf("r2 - %d\n", d2);
  135                   d3 = direction(l1, l2, r3);
  136                   printf("r3 - %d\n", d3);
  137                   d4 = direction(l1, l2, r4);
  138                   printf("r4 - %d\n", d4);
  139 } /* FUNCTION process */
  140 
  141               int main()
  142 {
  143     /* main */
  144     int i;
  145 
  146     init();
  147     for (i=0; i<numberOfTimes; i++)
  148         {
  149             /* while */
  150             getInput();
  151             process();
  152         } /* while */
  153 
  154     return EXIT_SUCCESS;
  155 } /* main */
  156 
  157