Computer Programming Contest Preparation

ToolBox - Source for: 113/11364/a.c



/home/toolbox/public_html/solutions/113/11364/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-11
   20  * Purpose: fun
   21  * Problem: 11364 - optimal parking
   22  * calculate distance between mon and max, double it, if distance was even subtract 2
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  */
   28 
   29 int numberOfTimes;
   30 int mn;
   31 int mx;
   32 
   33 void init()
   34 {
   35     /* FUNCTION init */
   36     scanf("%d ", &numberOfTimes);
   37 } /* FUNCTION init */
   38 
   39 void dump()
   40 {
   41     /* FUNCTION dump */
   42 } /* FUNCTION dump */
   43 
   44 void getInput()
   45 {
   46     /* FUNCTION getInput */
   47     int i;
   48     int cnt;
   49     int tmp;
   50 
   51     mn = 10000;
   52     mx = 0;
   53     scanf(" %d ", &cnt);
   54     for (i=0; i<cnt; i++)
   55         {
   56             /* read each shop location */
   57             scanf(" %d ", &tmp);
   58             if (tmp < mn)
   59                 {
   60                     mn = tmp;
   61                 }
   62             if (tmp > mx)
   63                 {
   64                     mx = tmp;
   65                 }
   66         } /* read each shop location */
   67 } /* FUNCTION getInput */
   68 
   69 void process()
   70 {
   71     /* FUNCTION process */
   72     int tmp;
   73 
   74     tmp = mx - mn;
   75     /*
   76     if (0 == (tmp % 2)) { tmp = tmp - 1; }
   77     */
   78     tmp = tmp * 2;
   79     printf("%d\n", tmp);
   80 } /* FUNCTION process */
   81 
   82 int main()
   83 {
   84     /* main */
   85     int i;
   86 
   87     init();
   88     for (i=0; i<numberOfTimes; i++)
   89         {
   90             /* while */
   91             getInput();
   92             process();
   93         } /* while */
   94 
   95     return EXIT_SUCCESS;
   96 } /* main */
   97 
   98