-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path591_Box_of_Bricks.java
39 lines (36 loc) · 1.12 KB
/
591_Box_of_Bricks.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int setNumber = 1;
int avgHeight;
int i;
int minimumMoves;
int heightSum;
int stackHeight;
int stackCount;
while(true){
stackCount = in.nextInt();
if(stackCount == 0){
break;
}
int[] stackArray = new int[stackCount];
heightSum = 0;
minimumMoves = 0;
for (i = 0; i < stackCount; i++) {
stackHeight = in.nextInt();
stackArray[i] = stackHeight;
heightSum += stackHeight;
}
avgHeight = heightSum/stackCount;
for (int stack :stackArray ) {
if(stack > avgHeight){
minimumMoves += stack-avgHeight;
}
}
System.out.println("Set #" + setNumber++);
System.out.println("The minimum number of moves is " + minimumMoves + ".");
System.out.println("");
}
}
}