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

 
(사용자 3명의 중간 판 12개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;SWEA 2072 홀수만 더하기
{{SWEA
* https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5QSEhaA5sDFAUq
|난이도=1
 
|링크=https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5QSEhaA5sDFAUq
{{SWEA 헤더}}
}}
{{SWEA 난이도 1-1}}
* 홀수(2로 나눈 나머지가 1)이면 더한다.
|}


==C++==
==C++==
<source lang='cpp'>
<syntaxhighlight lang='cpp'>
#include <iostream>
#include <iostream>
using namespace std;
using namespace std;
23번째 줄: 22번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>


==Java==
==Java==
<source lang='java'>
<syntaxhighlight lang='java'>
import java.util.*;
import java.util.*;
public class Solution {
public class Solution {
42번째 줄: 41번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>


==Python==
==Python==
<source lang='python'>
<syntaxhighlight lang='python'>
#kcy_code2
k = int(input())
for i in range(k):
    j = list(map(int, input().split()))
    sum_num = 0
    for y in range(len(j)):
        if j[y] % 2 != 0:
            sum_num = sum_num + j[y]
        else:
            continue
    print("#%d" %(i+1), sum_num)
</syntaxhighlight>
<syntaxhighlight lang='python'>
T = int(input())
T = int(input())
for tc in range(T) :
for tc in range(T) :
51번째 줄: 63번째 줄:
     res = sum(n for n in nums if n%2==1)
     res = sum(n for n in nums if n%2==1)
     print( f"#{tc+1} {res}" )
     print( f"#{tc+1} {res}" )
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[SWEA-2046 스탬프 찍기]]
* [[SWEA 2046 스탬프 찍기]]
* [[SWEA-2071 평균값 구하기]]
* [[SWEA 2071 평균값 구하기]]
* [[SWEA-2070 큰 놈, 작은 놈, 같은 놈]]
* [[SWEA 2070 큰 놈, 작은 놈, 같은 놈]]
 
==참고==
* https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5QSEhaA5sDFAUq

2023년 8월 25일 (금) 01:39 기준 최신판

1 개요[ | ]

SWEA 2072 홀수만 더하기

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[ | ]

#kcy_code2
k = int(input())
for i in range(k):
    j = list(map(int, input().split()))
    sum_num = 0
    for y in range(len(j)):
        if j[y] % 2 != 0:
            sum_num = sum_num + j[y]
        else:
            continue
    print("#%d" %(i+1), sum_num)
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 같이 보기[ | ]

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