Computer Programming Contest Preparation

ToolBox - Source for: 5/579/b.c



/home/toolbox/public_html/solutions/5/579/b.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 #define MAX_LENGTH 20
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2014-11-17
   20  * Purpose: fun
   21  * Problem: 579 - Clockhands
   22  */
   23 
   24 /*
   25  * This template reads data until a terminating value is reached.
   26  */
   27 
   28 char line[MAX_LENGTH];
   29 int hour;
   30 int minute;
   31 
   32 void init()
   33 {
   34     /* FUNCTION init */
   35 } /* FUNCTION init */
   36 
   37 void dump()
   38 {
   39     /* FUNCTION dump */
   40 } /* FUNCTION dump */
   41 
   42 int getInput()
   43 {
   44     /* FUNCTION getInput */
   45     int dataReadFlag;
   46     int i;
   47 
   48     scanf(" %s ", line);
   49     if ( ':' == line[2])
   50         {
   51             /* 2 digit hour */
   52             hour = 10 * (line[0] - '0') + (line[1] - '0');
   53             i = 3;
   54         } /* 2 digit hour */
   55     else
   56         {
   57             /* 1 digit hour */
   58             hour = line[0] - '0';
   59             i = 2;
   60         } /* 1 digit hour */
   61 
   62     minute = 10 * (line[i] - '0') + (line[i+1] - '0');
   63     dataReadFlag = (0 != hour) || (0 != minute);
   64     return (dataReadFlag);
   65 } /* FUNCTION getInput */
   66 
   67 void process()
   68 {
   69     /* FUNCTION process */
   70     double angle;
   71 
   72     /* adjust hour to degrees */
   73     hour = hour * 30;
   74     /* adjust minute to degrees */
   75     minute = minute * 6;
   76 
   77     angle = hour + (minute / 12.0);
   78     if (angle < minute)
   79         angle = minute - angle;
   80     else
   81         angle = angle - minute;
   82 
   83     printf("%.3lf\n", angle);
   84 } /* FUNCTION process */
   85 
   86 int main()
   87 {
   88     /* main */
   89     int moreToDo;
   90 
   91     init();
   92     moreToDo = getInput();
   93     while (moreToDo)
   94         {
   95             /* while */
   96             process();
   97             moreToDo = getInput();
   98         } /* while */
   99 
  100     return EXIT_SUCCESS;
  101 } /* main */
  102