프로그래밍 공부

BOJ/백준 3058번 짝수를 찾아라 본문

Problem Solving/Baekjoon Online Judge

BOJ/백준 3058번 짝수를 찾아라

khj1999 2019. 5. 16. 02:56

https://www.acmicpc.net/problem/3058

 

3058번: 짝수를 찾아라

입력은 T개의 테스트 데이터로 구성된다. 입력의 첫 번째 줄에는 입력 데이터의 수를 나타내는 정수 T가 주어진다. 각 테스트 데이터는 한 줄로 구성되어 있고, 7개의 자연수가 공백으로 구분되어 있다. 입력으로 주어지는 자연수는 1보다 크거나 같고, 100보다 작거나 같다. 7개의 자연수 중 적어도 하나는 짝수이다.

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t;
        t = sc.nextInt();
        int arr[][] = new int[t][7];
        for(int i = 0; i < t; i++) {
            for(int j = 0; j < arr[i].length; j++) {
                arr[i][j] = sc.nextInt(); 
            }
        }
        for(int i = 0; i < t; i++) {
            int sum = 0 , mim = 100
            for(int j = 0; j < arr[i].length; j++) {
                if(arr[i][j] % 2 == 0) {
                    sum += arr[i][j];
                    if(mim > arr[i][j]) {
                        mim = arr[i][j];
                    }
                }
            }
            System.out.println(sum+" "+mim);
        }
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

배열 인덱스 안에 있는 짝수의 합과 최솟값을 출력하면 되는 문제이다.

 

아직 잘 모르는 초보이니 오류지적 해주시면 감사하겟습니다.

Comments