Computer Programming Contest Preparation

ToolBox - Source for: 116/11683/b.c



/home/toolbox/public_html/solutions/116/11683/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 #define SIZE 10002
   15 
   16 /*
   17  *  Author: Isaac Traxler
   18  *    Date: 2014-10-26
   19  * Purpose: UVA Hack-a-thon
   20  * Problem: 11683 - Laser Sculpture
   21  */
   22 
   23 /*
   24  * This template reads data until a terminating value is reached.
   25  */
   26 
   27 int a;
   28 int c;
   29 
   30 void dump()
   31 {
   32     /* FUNCTION dump */
   33 } /* FUNCTION dump */
   34 
   35 int getInput()
   36 {
   37     /* FUNCTION getInput */
   38     int dataReadFlag;
   39 
   40     scanf(" %d ", &a);
   41     if (0 == a)
   42         dataReadFlag = FALSE;
   43     else
   44         {
   45             /* something read in */
   46             dataReadFlag = TRUE;
   47             scanf(" %d ", &c);
   48         } /* something read in */
   49     return (dataReadFlag);
   50 } /* FUNCTION getInput */
   51 
   52 void process()
   53 {
   54     /* FUNCTION process */
   55     int i;
   56     int h;
   57     int prev = a;
   58     int tot = 0;
   59 
   60     for (i=0; i<c; i++)
   61         {
   62             /* for each column */
   63             scanf(" %d ", &h);
   64             DEBUG printf("height=%d\n", h);
   65             if (prev > h)
   66                 {
   67                     /* some turned on that were off */
   68                     tot = tot + prev - h;
   69                 } /* some turned on that were off */
   70             prev = h;
   71         } /* for each column */
   72 
   73     printf("%d\n", tot);
   74 } /* FUNCTION process */
   75 
   76 int main ()
   77 {
   78     /* main */
   79     int moreToDo;
   80 
   81     moreToDo = getInput();
   82     while (moreToDo)
   83         {
   84             /* while */
   85             process();
   86             moreToDo = getInput();
   87         } /* while */
   88 
   89     return EXIT_SUCCESS;
   90 } /* main */
   91