m = int(input())out = []total = count = 0for _ in range(m): k, *scores = map(int, input().split()) s = sum(scores) out.append(f"{s / k:.2f}") total += s # 학년 평균은 반 평균이 아니라 점수 합과 학생 수를 모아서 구한다 count += kout.append(f"{total / count:.2f}")print("\n".join(out))
JavaScriptmain.js · 15 行
const lines = require("fs").readFileSync(0, "utf8").split("\n");const m = Number(lines[0]);const out = [];let total = 0;let count = 0;for (let i = 1; i <= m; i++) { const [k, ...scores] = lines[i].trim().split(/\s+/).map(Number); let s = 0; for (const x of scores) s += x; out.push((s / k).toFixed(2)); total += s; // 학년 평균은 점수 합과 학생 수를 모아서 구한다 count += k;}out.push((total / count).toFixed(2));console.log(out.join("\n"));
TypeScriptmain.ts · 16 行
import { readFileSync } from "node:fs";const lines: string[] = readFileSync(0, "utf8").split("\n");const m: number = Number(lines[0]);const out: string[] = [];let total = 0;let count = 0;for (let i = 1; i <= m; i++) { const [k, ...scores]: number[] = lines[i].trim().split(/\s+/).map(Number); let s = 0; for (const x of scores) s += x; out.push((s / k).toFixed(2)); total += s; // 학년 평균은 점수 합과 학생 수를 모아서 구한다 count += k;}out.push((total / count).toFixed(2));console.log(out.join("\n"));
JavaMain.java · 26 行
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Locale;import java.util.StringTokenizer;public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int m = Integer.parseInt(in.readLine().trim()); StringBuilder out = new StringBuilder(); int total = 0, count = 0; for (int i = 0; i < m; i++) { StringTokenizer st = new StringTokenizer(in.readLine()); int k = Integer.parseInt(st.nextToken()); int s = 0; for (int j = 0; j < k; j++) s += Integer.parseInt(st.nextToken()); // int끼리 나누면 몫만 남으니 한쪽을 double로 out.append(String.format(Locale.ROOT, "%.2f", (double) s / k)).append('\n'); total += s; count += k; } out.append(String.format(Locale.ROOT, "%.2f", (double) total / count)).append('\n'); System.out.print(out); }}
C#Main.cs · 26 行
using System;using System.Globalization;using System.Linq;using System.Text;class Program{ static void Main() { int m = int.Parse(Console.ReadLine()); var sb = new StringBuilder(); int total = 0, count = 0; for (int i = 0; i < m; i++) { int[] p = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); int k = p[0]; int s = p.Skip(1).Sum(); // int끼리 나누면 몫만 남으니 한쪽을 double로 sb.Append(((double)s / k).ToString("F2", CultureInfo.InvariantCulture)).Append('\n'); total += s; count += k; } sb.Append(((double)total / count).ToString("F2", CultureInfo.InvariantCulture)).Append('\n'); Console.Write(sb); }}
C++main.cpp · 24 行
#include <iomanip>#include <iostream>int main() { std::ios::sync_with_stdio(false); int m; std::cin >> m; int total = 0, count = 0; std::cout << std::fixed << std::setprecision(2); for (int i = 0; i < m; i++) { int k; std::cin >> k; int s = 0; for (int j = 0; j < k; j++) { int x; std::cin >> x; s += x; } std::cout << static_cast<double>(s) / k << "\n"; total += s; count += k; } std::cout << static_cast<double>(total) / count << "\n";}
Cmain.c · 20 行
#include <stdio.h>int main(void) { int m, k, x; int total = 0, count = 0; scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%d", &k); int s = 0; for (int j = 0; j < k; j++) { scanf("%d", &x); s += x; } printf("%.2f\n", (double)s / k); /* (double)로 바꾼 뒤에 나눈다 */ total += s; count += k; } printf("%.2f\n", (double)total / count); return 0;}
Craykonmain.cray · 17 行
m = コンソール.行読み().数に();total = 0;count = 0;繰り返す (i = 0; i < m; i++){ p = コンソール.数読み(); k = p[0]; s = 0; 繰り返す (j = 1; j <= k; j++) { s += p[j]; } コンソール.書く(文字.桁そろえ(s / k, 2)); total += s; // 학년 평균은 점수 합과 학생 수를 모아서 구한다 count += k;}コンソール.書く(文字.桁そろえ(total / count, 2));