본문 바로가기
2-2. 코딩테스트 문제집(SW Expert Academy)/SWEA(D1)

[SWEA] D1: 평균값 구하기(2071) 해설

by cogito21_cpp 2025. 1. 31.
반응형

문제

- 문제 링크: 평균값 구하기

 

풀이

(C++)

solution 1)

- 시간 복잡도: 

더보기
더보기
#include<iostream>
#include <cmath>

using namespace std;

int main(int argc, char** argv)
{
	int test_case;
	int T;
	cin>>T;
    
	for(test_case = 1; test_case <= T; ++test_case)
	{
        double total = 0;
        for (int i = 0; i < 10; ++i) {
             int num;
            cin >> num;
            total += num;
        }
        cout << "#" << test_case << " " << round(total/10) << endl;
	}
	return 0;
}

 

(Java)

solution 1)

- 시간 복잡도: 

더보기
더보기
import java.util.*

 

(Python)

solution 1)

- 시간 복잡도: 

더보기
더보기
import sys

T = int(input())

for test_case in range(1, T + 1):
    total = 0
    arr = list(map(int, input().split()))
    for i in arr:
        total += i
    answer = round(total / len(arr))
    print(f"#{test_case} {answer}")

 

반응형