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

42번째 줄: 42번째 줄:
     }
     }
}
}
</source>
==Python==
<source lang='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}" )
</source>
</source>



2019년 1월 14일 (월) 02:28 판

1 개요

SWEA 2072 홀수만 더하기
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 }}