https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=7&problem=532&mosmsg=Submission+received+with+ID+17576677 困難度 ★ *注意每筆後面要多加一行換行以免測資過不了
import java.util.*;
public class test {
public static void main(String[] args) {
Scanner scn =new Scanner (System.in);
int n,count=0;
while((n=scn.nextInt())!=0){
int arr[]=new int [50],tot=0,max=0;
for(int i=0;i<n;i++){
arr[i]=scn.nextInt();
tot+=arr[i];
}
tot/=n;
for(int i=0;i<n;i++){
if(tot<arr[i])max+=arr[i]-tot;
}
System.out.printf("Set #%d\n",++count);
System.out.printf("The minimum number of moves is %d.\n",max);
}
}
}
/*
題目:Q591:Box of Bricks
作者:1010
時間:西元 2016 年 6 月 */