"SWEA 2071 평균값 구하기"의 두 판 사이의 차이

1번째 줄: 1번째 줄:
==개요==
==개요==
;SWEA 2071 평균값 구하기
;SWEA 2071 평균값 구하기
* https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5QRnJqA5cDFAUq
* 모두 더한 다음 개수 N으로 나눈다.


{{SWEA 헤더}}
{{SWEA 헤더}}

2019년 1월 21일 (월) 00:05 판

1 개요

SWEA 2071 평균값 구하기
  • 모두 더한 다음 개수 N으로 나눈다.
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 1-1

2 C++

#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int T, n;
    cin >> T;
    for(int tc=1; tc<=T; tc++) {
        int sum = 0;
        for(int i=0; i<10; i++) {
            cin >> n;
            sum+=n;
        }
        cout << "#" << tc << " " << round(sum/10.0) << endl;
    }
}

3 Java

import java.util.*;
public class Solution {
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]) {
        int T = sc.nextInt();
        for(int tc=1; tc<=T; tc++) {
            int sum = 0;
            for(int i=0; i<10; i++) sum += sc.nextInt();
            System.out.format( "#%d %.0f\n", tc, sum/10.0);            
        }
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}