Computer Programming Contest Preparation

ToolBox - Source for: 125/12555/a.c



/home/toolbox/public_html/solutions/125/12555/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 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /* fprintf(stderr, "functionName: message", varslist); */
   17 
   18 /*
   19  *  Author: Isaac Traxler
   20  *    Date: 2021-12-16
   21  * Purpose: fun
   22  * Problem: 12555 - Baby Me
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  */
   28 
   29 int numberOfTimes;
   30 double a;
   31 double b;
   32 char line[100];
   33 int slen;
   34 
   35 void init()
   36 {
   37     /* FUNCTION init */
   38     scanf("%d ", &numberOfTimes);
   39 } /* FUNCTION init */
   40 
   41 void dump()
   42 {
   43     /* FUNCTION dump */
   44 } /* FUNCTION dump */
   45 
   46 void getInput()
   47 {
   48     /* FUNCTION getInput */
   49     int tot;
   50     int i;
   51 
   52     fgets(line, 99, stdin);
   53     line[strlen(line)-1] = 0;
   54     slen = strlen(line);
   55     i = 0;
   56     tot = 0;
   57     while (! isdigit(line[i]))
   58         {
   59             i++;
   60         }
   61     while (isdigit(line[i]))
   62         {
   63             /* extract first number */
   64             tot = (tot * 10) + (line[i] - '0');
   65             i++;
   66         } /* extract first number */
   67     a = tot + 0l;
   68     while ((slen > i) && (! isdigit(line[i])))
   69         {
   70             i++;
   71         }
   72     if (slen < i)
   73         {
   74             b = 0l;
   75         }
   76     else
   77         {
   78             /* extract second number */
   79             tot = 0;
   80             while (isdigit(line[i]))
   81                 {
   82                     /* extract first number */
   83                     tot = (tot * 10) + (line[i] - '0');
   84                     i++;
   85                 } /* extract first number */
   86             b = tot + 0l;
   87         } /* extract second number */
   88 } /* FUNCTION getInput */
   89 
   90 void process()
   91 {
   92     /* FUNCTION process */
   93     double tot;
   94 
   95     tot = (a * 0.5l) + (b * 0.05l);
   96     sprintf(line, "%lf", tot);
   97     slen = strlen(line);
   98     while ((0 < slen) && (('.' == line[slen - 1]) || ('0' == line[slen - 1])))
   99         {
  100             slen--;
  101         }
  102     line[slen] = 0;
  103     printf("%s\n", line);
  104 } /* FUNCTION process */
  105 
  106 int main()
  107 {
  108     /* main */
  109     int i;
  110 
  111     init();
  112     for (i=1; i<=numberOfTimes; i++)
  113         {
  114             /* while */
  115             getInput();
  116             printf("Case %d: ", i);
  117             process();
  118         } /* while */
  119 
  120     return EXIT_SUCCESS;
  121 } /* main */
  122 
  123