HDACM2088
此题只要先求出平均值,然后把低于平均值的个数求出来,并且求和,最后再把average*个数-sum就能得出需要移动的个数,
注意:每两行之间要有一个空行
import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);boolean isFirst = true;while(sc.hasNext()){int n = sc.nextInt();if (n==0) {break;}if (isFirst) {isFirst = false;}else {System.out.println();}int[] m = new int[n];int sum = 0;for (int i = 0; i < m.length; i++) {m[i] = sc.nextInt();sum += m[i];}int average = sum/n;sum = 0;int k = 0;for (int i = 0; i < m.length; i++) {if (m[i]<average) {sum += m[i];k++;}}System.out.println(average*k-sum);}}
}