"SWEA 2072 홀수만 더하기"의 두 판 사이의 차이

1번째 줄: 1번째 줄:
==개요==
==개요==
;SWEA 2072 홀수만 더하기
;SWEA 2072 홀수만 더하기
* https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5QSEhaA5sDFAUq
* 홀수(2로 나눈 나머지가 1)이면 더한다.  


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

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

1 개요

SWEA 2072 홀수만 더하기
  • 홀수(2로 나눈 나머지가 1)이면 더한다.
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 1-1

2 C++

#include <iostream>
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;
            if( n%2 == 1 ) sum+=n;
        }
        cout << "#" << tc << " " << sum << 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 j=0; j<10; j++ ) {
             	int n = sc.nextInt();
                if( n%2 == 1 ) sum+=n;
            }
            System.out.format("#%d %d\n", tc, sum);
        }
    }
}

4 Python

T = int(input())
for tc in range(T) :
    nums = map(int,input().split())
    res = sum(n for n in nums if n%2==1)
    print( f"#{tc+1} {res}" )

5 같이 보기

6 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}