/home/toolbox/public_html/solutions/5/591/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 <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 #define MAX_COLS 101
15
16 /* fprintf(stderr, "functionName: message", varslist); */
17
18 /*
19 * Author: Isaac Traxler
20 * Date: 2014-10-29
21 * Purpose: fun
22 * Problem: 591 - Box of Bricks
23 */
24
25 /*
26 * This template reads data a specified number of times.
27 */
28
29 int colCnt;
30 int cols[MAX_COLS];
31 int tot;
32
33 void init()
34 {
35 /* FUNCTION init */
36 } /* FUNCTION init */
37
38 void dump()
39 {
40 /* FUNCTION dump */
41 } /* FUNCTION dump */
42
43 int getInput()
44 {
45 /* FUNCTION getInput */
46 int i;
47 int dataReadFlag = FALSE;
48
49 scanf(" %d ", &colCnt);
50 if (0 != colCnt)
51 {
52 /* more data to process */
53 dataReadFlag = TRUE;
54 tot = 0;
55 for(i=0; i<colCnt; i++)
56 {
57 /* read each column */
58 scanf(" %d ", &cols[i]);
59 tot = tot + cols[i];
60 } /* read each column */
61 } /* more data to process */
62 return dataReadFlag;
63 } /* FUNCTION getInput */
64
65 void process()
66 {
67 /* FUNCTION process */
68 int i;
69 int avg;
70
71 avg = tot / colCnt;
72 tot = 0;
73 for (i=0; i<colCnt; i++)
74 {
75 /* for each col */
76 if (cols[i] > avg)
77 {
78 tot = tot + cols[i] - avg;
79 }
80 } /* for each col */
81 printf("The minimum number of moves is %d.\n\n", tot);
82
83 } /* FUNCTION process */
84
85 int main ()
86 {
87 /* main */
88 int i = 0;
89 int moreToDo;
90
91 moreToDo = getInput();
92 while (moreToDo)
93 {
94 /* while */
95 i++;
96 printf("Set #%d\n", i);
97 process();
98 moreToDo = getInput();
99 } /* while */
100
101 return EXIT_SUCCESS;
102 } /* main */
103
104