공부하기/백준

[Java] 백준 풀기 10833 - 할로윈의 사탕

XEV 2023. 12. 20. 23:40

자바 백준 10178번

브론즈 3

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

 

10178번: 할로윈의 사탕

할로윈데이에 한신이네는 아부지가 사탕을 나눠주신다. 하지만 한신이의 형제들은 서로 사이가 좋지않아 서른이 넘어서도 사탕을 공정하게 나누어 주지 않으면 서로 싸움이 난다. 매년 할로윈

www.acmicpc.net

 

 

 

 

 

문제 보기

분류: 수학, 사칙연산

 

 

 

 

 

코드 보기

import java.util.Scanner;
public class CandyDistribution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 테스트 케이스의 수 입력
int testCases = sc.nextInt();
for (int i = 0; i < testCases; i++) {
// 사탕의 개수와 형제의 수 입력
int candyCount = sc.nextInt();
int siblingsCount = sc.nextInt();
// 각 형제들에게 나눠주는 사탕의 수 계산
int candiesPerSibling = candyCount / siblingsCount;
// 아부지가 받게 되는 사탕의 수 계산
int dadGets = candyCount % siblingsCount;
// 결과 출력
System.out.println("You get " + candiesPerSibling + " piece(s) and your dad gets " + dadGets + " piece(s).");
}
}
}