프로그래밍 공부
BOJ/백준 3058번 짝수를 찾아라 본문
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
|
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 |
배열 인덱스 안에 있는 짝수의 합과 최솟값을 출력하면 되는 문제이다.
아직 잘 모르는 초보이니 오류지적 해주시면 감사하겟습니다.
'Problem Solving > Baekjoon Online Judge' 카테고리의 다른 글
BOJ/백준 2566번 최댓값 (0) | 2019.05.16 |
---|---|
BOJ/백준 2857번 FBI (0) | 2019.05.16 |
BOJ/백준 17174번 전체 계산 횟수 (0) | 2019.05.16 |
BOJ/백준 17173번 배수들의 합 (0) | 2019.05.16 |
BOJ/백준 16673번 고려대학교에는 공식 와인이 있다 (0) | 2019.05.06 |
Comments