summaryrefslogtreecommitdiff
path: root/591/bricks.c
diff options
context:
space:
mode:
authorAditya Naik2018-05-12 21:00:48 -0400
committerAditya Naik2018-05-12 21:00:48 -0400
commit6fc7554c74c5745c8890f2367628d3d1cf3ddac7 (patch)
tree7593c2050df9e5290c8c64bc63cfa472769ef6de /591/bricks.c
parent240b65a7e9c514acde1cb33b24053cdcac06c7e8 (diff)
huatuo and bricks
Diffstat (limited to '591/bricks.c')
-rw-r--r--591/bricks.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/591/bricks.c b/591/bricks.c
new file mode 100644
index 0000000..bd4d047
--- /dev/null
+++ b/591/bricks.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int main(){
+ int n, j=0;
+ scanf("%d", &n);
+ while(n>0){
+ j++;
+ int heights[100], avg, sum=0, i, moves=0, move, h;
+ for(i=0; i<n; i++){
+ scanf("%d", &h);
+ sum+=h;
+ heights[i]=h;
+ }
+ avg = sum/n;
+ for(i=0; i<n; i++){
+ move = avg-heights[i];
+ moves += (move < 0 ? move*-1 : move);
+ }
+ printf("Set #%d\nThe minimum number of moves is %d.\n\n", j, moves/2);
+ scanf("%d", &n);
+ }
+ return 0;
+}