Computer Programming Contest Preparation

ToolBox - Source for: 105/10550/a.c



/home/toolbox/public_html/solutions/105/10550/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: 2014-10-22
   18  * Purpose: fun
   19  * Problem: 10550 - Combination Lock
   20  */
   21 
   22 /*
   23  * This template reads data until a terminating value is reached.
   24  */
   25 
   26 int start;
   27 int one;
   28 int two;
   29 int three;
   30 
   31 void init()
   32 {
   33     /* FUNCTION init */
   34 } /* FUNCTION init */
   35 
   36 void dump()
   37 {
   38     /* FUNCTION dump */
   39 } /* FUNCTION dump */
   40 
   41 int getInput()
   42 {
   43     /* FUNCTION getInput */
   44     int dataReadFlag;
   45 
   46     scanf(" %d %d %d %d ", &start, &one, &two, &three);
   47     dataReadFlag = (0 != start) || (0 != one) || (0 != two) || (0 != three);
   48     /* convert all to degrees */
   49     start = start * 9;
   50     one = one * 9;
   51     two = two * 9;
   52     three = three * 9;
   53     return (dataReadFlag);
   54 } /* FUNCTION getInput */
   55 
   56 void process()
   57 {
   58     /* FUNCTION process */
   59     int degrees = 0; /* 1080; /* initial 2 turns and 1 turn after first number */
   60 
   61     /* first turn */
   62     DEBUG printf("1 start=%d  one=%d\n", start, one);
   63     if (start > one)
   64         {
   65             /* need another round */
   66             DEBUG printf("1 start > one: before %d\n", degrees);
   67             degrees = degrees + start - one;
   68             DEBUG printf("1 start > one: after %d\n", degrees);
   69         } /* need another round */
   70     else
   71         {
   72             /* just a little more to go  */
   73 
   74             DEBUG printf("1 start <= one: before %d\n", degrees);
   75             degrees = degrees + 360 - one + start;
   76             DEBUG printf("1 start <= one: after %d\n", degrees);
   77         } /* just a little more to go  */
   78 
   79     DEBUG printf(" 1 %d\n", degrees);
   80     /* second turn */
   81     DEBUG printf("2 one=%d   two=%d\n", one, two);
   82     if (one > two)
   83         {
   84             /* just a little to go */
   85             DEBUG printf("2 one > two: before %d\n", degrees);
   86             degrees = degrees + 360  - one + two;
   87             DEBUG printf("2 one > two: after %d\n", degrees);
   88         } /* just a little to go */
   89     else
   90         {
   91             /* need a full turn  almost */
   92             DEBUG printf("2 one <= two: before %d\n", degrees);
   93             degrees = degrees + two - one;
   94             DEBUG printf("2 one <= two: after %d\n", degrees);
   95         } /* need a full turn  almost */
   96     DEBUG printf("2 %d\n", degrees);
   97 
   98     /* third turn */
   99     DEBUG printf("3 two=%d   three=%d\n", two, three);
  100     if (two > three)
  101         {
  102             /* need another round */
  103             degrees = degrees + two - three;
  104         } /* need another round */
  105     else
  106         {
  107             /* just a little more to go  */
  108             degrees = degrees + 360 - three + two;
  109         } /* just a little more to go  */
  110 
  111     degrees = degrees + 1080;
  112     printf("%d\n", degrees);
  113 } /* FUNCTION process */
  114 
  115 int main ()
  116 {
  117     /* main */
  118     int moreToDo;
  119 
  120     init();
  121     moreToDo = getInput();
  122     while (moreToDo)
  123         {
  124             /* while */
  125             process();
  126             moreToDo = getInput();
  127         } /* while */
  128 
  129     return EXIT_SUCCESS;
  130 } /* main */
  131