From 4b123d0f3482f13d6156ddadf1997085a63f998f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=9C=A8=E6=9C=A8sir?= <1078213484@qq.com> Date: Thu, 3 Aug 2023 00:56:42 +0000 Subject: [PATCH] =?UTF-8?q?update=20problems/0008.=E6=91=86=E5=B9=B3?= =?UTF-8?q?=E7=A7=AF=E6=9C=A8.md.=20=E6=91=86=E5=B9=B3=E7=A7=AF=E6=9C=A8ja?= =?UTF-8?q?va=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王木木sir <1078213484@qq.com> --- ...06\345\271\263\347\247\257\346\234\250.md" | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git "a/problems/0008.\346\221\206\345\271\263\347\247\257\346\234\250.md" "b/problems/0008.\346\221\206\345\271\263\347\247\257\346\234\250.md" index 6443c52..b340789 100644 --- "a/problems/0008.\346\221\206\345\271\263\347\247\257\346\234\250.md" +++ "b/problems/0008.\346\221\206\345\271\263\347\247\257\346\234\250.md" @@ -33,7 +33,32 @@ int main() { ## Java ```Java +import java.util.*; +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + while (sc.hasNextInt()) { + int n = sc.nextInt(); + if (n == 0) break; + int[] blocks = new int[n]; + int sum = 0; + for (int i = 0; i < n; i++) { + blocks[i] = sc.nextInt(); + sum += blocks[i]; + } + int avg = sum / n; + int res = 0; + for (int block : blocks) { + if (block - avg > 0) { + res += block - avg; + } + } + System.out.println(res); + System.out.println(); + } + } +} ``` ## python -- Gitee