자바 백준 10103번
브론즈 3
https://www.acmicpc.net/problem/10103
10103번: 주사위 게임
첫 라운드는 상덕이의 승리이다. 따라서 창영이는 6점을 잃게 된다. 두 번째 라운드는 두 사람의 숫자가 같기 때문에, 아무도 점수를 잃지 않고 넘어간다. 세 번째 라운드의 승자는 창영이이기
www.acmicpc.net
문제 보기

분류: 수학, 구현, 사칙연산, 시뮬레이션
코드 보기
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int scoreA = 100;
int scoreB = 100;
playGame(sc, n, scoreA, scoreB);
}
public static void playGame(Scanner sc, int n, int scoreA, int scoreB) {
for (int i = 0; i < n; i++) {
int diceA = sc.nextInt();
int diceB = sc.nextInt();
if (diceA > diceB) {
scoreB -= diceA;
} else if (diceA < diceB) {
scoreA -= diceB;
}
}
displayScores(scoreA, scoreB);
}
public static void displayScores(int scoreA, int scoreB) {
System.out.println(scoreA);
System.out.println(scoreB);
}
}
'공부하기 > 백준' 카테고리의 다른 글
| [Python] 백준 풀기 2965 - 캥거루 세마리 (0) | 2023.10.30 |
|---|---|
| [Java] 백준 풀기 2592 - 대표값 (0) | 2023.10.27 |
| [Java] 백준 풀기 15969 - 행복 (1) | 2023.10.25 |
| [Java] 백준 풀기 6749 - Next in line (0) | 2023.10.24 |
| [Java] 백준 풀기 10214 - Baseball (2) | 2023.10.23 |