문제링크
https://www.acmicpc.net/problem/2851
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int arr[] = new int[10];
for(int i=0;i<10;i++)
arr[i] = sc.nextInt();
int result = 0;
for(int i=0;i<10;i++) {
int sum = 0;
for(int j=0;j<=i;j++)
sum += arr[j];
if(Math.abs(100 -result) == Math.abs(100-sum)) result = (result>sum)?result:sum;
else if(Math.abs(100-result) > Math.abs(100-sum)) result = sum;
}
System.out.println(result);
}
}
'알고리즘 > 백준' 카테고리의 다른 글
[JAVA]백준_2810_컵홀더 (0) | 2021.02.25 |
---|---|
[JAVA]백준_3985_롤케이크 (0) | 2021.02.25 |
[JAVA]백준_2559_수열 (0) | 2021.02.25 |
[JAVA][C++]백준_2941_크로아티아 알파벳 (0) | 2021.02.25 |
[JAVA]백준_2578_빙고 (0) | 2021.02.25 |