Computer Programming Contest Preparation

ToolBox - Source for: 114/11455/a.c



/home/toolbox/public_html/solutions/114/11455/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: 2016-09-06
   20  * Purpose: fun
   21  * Problem: 11455 - Behold My Quadrangle
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 int numberOfTimes;
   29 int a[4];
   30 
   31 void init()
   32 {
   33     /* FUNCTION init */
   34     scanf("%d ", &numberOfTimes);
   35 } /* FUNCTION init */
   36 
   37 void dump()
   38 {
   39     /* FUNCTION dump */
   40 } /* FUNCTION dump */
   41 
   42 int compare(const void *a, const void *b)
   43 {
   44     /* FUNCTION compare */
   45     return ( *(int*)a - *(int*)b );
   46 } /* FUNCTION compare */
   47 
   48 
   49 void getInput()
   50 {
   51     /* FUNCTION getInput */
   52     scanf(" %d %d %d %d ", &a[0], &a[1], &a[2], &a[3]);
   53     qsort(a, 4, sizeof(int), compare);
   54     DEBUG printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]);
   55 } /* FUNCTION getInput */
   56 
   57 void process()
   58 {
   59     /* FUNCTION process */
   60     int tmp;
   61 
   62     if ((a[0] == a[1]) && (a[0] == a[2]) && (a[0] == a[3]))
   63         {
   64             /* all sides equal -- must be a square */
   65             printf("square\n");
   66         } /* all sides equal -- must be a square */
   67     else if ((a[0] == a[1]) && (a[2] == a[3]))
   68         {
   69             /* 2 opposite sides are equal -- must be a rectangle */
   70             printf("rectangle\n");
   71         } /* 2 opposite sides are equal -- must be a rectangle */
   72     else
   73         {
   74             /* is it a quadrangle */
   75             /* to be a quadrangle, the 4 sides must connect. Since a[4] is the longest side, a[0] could go to
   76              * a[2] that goes to a[1] (second longest side opposite longest side). In this example a[0] + a[1]
   77              * must be longer than the difference between a[4] and a[3].
   78              */
   79             tmp = a[3] - a[2];
   80             if ((a[0] + a[1]) > tmp)
   81                 {
   82                     /* quadrangle */
   83                     printf("quadrangle\n");
   84                 } /* quadrangle */
   85             else
   86                 printf("banana\n");
   87         } /* is it a quadrangle */
   88 } /* FUNCTION process */
   89 
   90 int main()
   91 {
   92     /* main */
   93     int i;
   94 
   95     init();
   96     for (i=0; i<numberOfTimes; i++)
   97         {
   98             /* while */
   99             getInput();
  100             process();
  101         } /* while */
  102 
  103     return EXIT_SUCCESS;
  104 } /* main */
  105 
  106