Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- */
- /**
- * @author ak47suk1
- *
- */
- import java.util.*;
- public class BoxOfBricks {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int caseCounter=0;
- Scanner s = new Scanner(System.in);
- while (s.hasNext()){
- int hi = s.nextInt();
- if (hi != 0){
- ArrayList<Integer> bricks1 = new ArrayList<Integer>();
- for (int A = 0; A < hi; A++) {
- bricks1.add(s.nextInt());}
- ++caseCounter;
- System.out.println("Case #" + caseCounter + ": "
- + getMinNum(bricks1));
- }
- }
- }
- public static Integer getMinNum(ArrayList<Integer> bricks1){
- Integer sum = 0, sum2=0;
- for (int B = 0; B < bricks1.size(); B++) {
- sum += bricks1.get(B);
- }
- int average = sum/bricks1.size();
- for (int C = 0; C < bricks1.size(); C++) {
- sum2 += Math.abs(average - bricks1.get(C));
- }
- return sum2/2;
- }
- }
Add Comment
Please, Sign In to add comment