搬動最少方塊

 avatar
user_3763047219
c_cpp
2 years ago
721 B
0
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
int main()
{
	int N = -1;
	int total = 0;
	int count = 0;
	int set = 0;
	while (N != 0) {
		scanf("%d", &N);
		if (N != 0) {
			int A[50] = { 0 };
			int A2[50] = { 0 };
			set = set + 1;
			total = 0;
			count = 0;
			for (int i = 0; i < N; i++) {
				scanf("%d", &A[i]);
			}
			for (int i = 0; i < N; i++) {
				total = total + A[i];
			}
			int mean = 0;
			mean = total / N;

			for (int i = 0; i < N; i++) {
				A2[i] = A[i] - mean;
			}
			for (int i = 0; i < N; i++) {
				if (A2[i] > 0) {
					count = count + A2[i];
				}
			}
			printf("Set #%d\n", set);
			printf("The minimum number of moves is %d.\n", count);
		}
	}
}