Home B2851. 슈퍼마리오
Post
Cancel

B2851. 슈퍼마리오

문제

image

제출 코드

image

  • 사용 알고리즘 : 구현
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package bronze;

import java.util.Scanner;

public class B2851_superMario {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int sum = 0;
		for(int i=0; i<10; i++) {
			int num = sc.nextInt();
			if(Math.abs(sum + num - 100) <= Math.abs(sum - 100)) {
				sum += num;
			}else break;
		}
		System.out.println(sum);
	}
}
This post is licensed under CC BY 4.0 by the author.