91. 搬動最少方塊

 avatar
user_6817964
c_cpp
2 years ago
633 B
0
Indexable
Never
#include <stdio.h> // printf
int main()
{
	int n[100], h[100][100];
	int num = 1;
	for(int k = 1; k <= 100; k++){
		scanf_s("%d", &n[num]);
		if (n[num] == 0)
			break;
		for (int i = 1; i <= n[num]; i++) {
			scanf_s("%d", &h[num][i]);
		}
		num++;
	
	}
	
	for (int i = 1; i < num; i++) {
		int sum = 0;
		for (int j = 1; j <= n[i]; j++) {
			sum += h[i][j];
		}
		int average = sum / n[i];
		int move = 0;
		for (int j = 1; j <= n[i]; j++) {
			if (h[i][j] > average) {
				move += h[i][j] - average;
			}
		}
		printf("Set #%d\n", i);
		printf("The minimum number of moves is %d.\n\n", move);
	}

}