๋ฌธ์ (์ถ์ฒ: https://www.acmicpc.net/problem/6177)
< Statistics >
๋ฌธ์  ํ์ด
1. ๋ชจ๋ ๊ฐ์ ๋ํ์ฌ N์ผ๋ก ๋๋๋ค.
2. ์ ๋ ฌํ ํ ๊ฐ์ด๋ฐ ๊ฐ์ ๊ตฌํ๋ค. (์ง์๊ฐ๋ผ๋ฉด ์ค๊ฐ 2๊ฐ์ ํ๊ท ์ ๊ตฌํ๋ค.)
my solution (Java)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class _6177_ { // Statistics
	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(bf.readLine());
		int arr[] = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			arr[i] = Integer.parseInt(bf.readLine());
			sum += arr[i];
		}
		System.out.println((double) sum / N);
		Arrays.sort(arr);
		if (N % 2 == 0) {
			sum = arr[N / 2 - 1] + arr[N / 2];
			System.out.println((double) sum / 2);
		} else {
			System.out.println(arr[N / 2]);
		}
	}
}๋ณ์)
N : ์ด ๊ฐ์
arr : ๊ฐ ์ ์ฅ ๋ฐฐ์ด
sum : ํฉ
์ด ๊ฐ์ N์ ์ ๋ ฅ๋ฐ๋๋ค. N๋งํผ ๊ฐ์ ์ ๋ ฅ๋ฐ์ arr์ ์ ์ฅํ๋ ๋์์ ํฉ์ ๊ตฌํ๋ค. ํฉ์ N์ผ๋ก ๋๋ ํ๊ท ๊ฐ์ ์ถ๋ ฅํ๋ค. arr์ ์ ๋ ฌ ํ N์ด ํ์๋ผ๋ฉด ์ค๊ฐ ๊ฐ์, ์ง์๋ผ๋ฉด ์ค๊ฐ ๊ฐ 2๊ฐ์ ํ๊ท ๊ฐ์ ์ถ๋ ฅํ๋ค.

'๐Algorithm > ๐ฅBaekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [Baekjoon] 11235_Polling (0) | 2024.11.04 | 
|---|---|
| [Baekjoon] 11609_Class Time (0) | 2024.11.01 | 
| [Baekjoon] 6160_Election Time (0) | 2024.10.29 | 
| [Baekjoon] 10527_Judging Troubles (0) | 2024.10.28 | 
| [Baekjoon] 11968_High Card Wins (0) | 2024.10.25 |