Computer Programming Contest Preparation

ToolBox - Source for: 121/12157/a.c



/home/toolbox/public_html/solutions/121/12157/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-7
   21  * Purpose: fun
   22  * Problem: 12157 - Tariff plan
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  */
   28 
   29 #define MILE 10
   30 #define JUICE 15
   31 
   32 int numberOfTimes;
   33 int mile;
   34 int juice;
   35 
   36 void init()
   37 {
   38     /* FUNCTION init */
   39     scanf("%d ", &numberOfTimes);
   40 } /* FUNCTION init */
   41 
   42 void dump()
   43 {
   44     /* FUNCTION dump */
   45 } /* FUNCTION dump */
   46 
   47 void getInput()
   48 {
   49     /* FUNCTION getInput */
   50     int i;
   51     int cnt;
   52     int tmp;
   53 
   54     mile = 0;
   55     juice = 0;
   56     scanf(" %d ", &cnt);
   57     for (i=0; cnt>i; i++)
   58         {
   59             /* get each call duration */
   60             scanf(" %d ", &tmp);
   61             mile = mile + ((tmp + 30) / 30);
   62             juice = juice + ((tmp + 60) / 60);
   63             DEBUG printf("(mile %d) (juice %d)\n", mile, juice);
   64         } /* get each call duration */
   65 } /* FUNCTION getInput */
   66 
   67 void process()
   68 {
   69     /* FUNCTION process */
   70     mile = mile * MILE;
   71     juice = juice * JUICE;
   72     if (mile < juice)
   73         {
   74             /* mile chepaer */
   75             printf("Mile %d\n", mile);
   76         } /* mile chepaer */
   77     else if (juice < mile)
   78         {
   79             /* juice chepaer */
   80             printf("Juice %d\n", juice);
   81         } /* juice chepaer */
   82     else
   83         {
   84             /* tie */
   85             printf("Mile Juice %d\n", mile);
   86         } /* tie */
   87 
   88 } /* FUNCTION process */
   89 
   90 int main()
   91 {
   92     /* main */
   93     int i;
   94 
   95     init();
   96     for (i=1; i<=numberOfTimes; i++)
   97         {
   98             /* while */
   99             getInput();
  100             printf("Case %d: ", i);
  101             process();
  102         } /* while */
  103 
  104     return EXIT_SUCCESS;
  105 } /* main */
  106 
  107