내가 생각했을때 문제에서 원하는부분
One line containing the number of contests, n(1 <= n <= 10^4).
One line containing the prize purse for each contest, w_1 ... w_n(1 <= w <= 10^5).
Output yes if the winnings can be distributed equally between three contestants, otherwise no.
내가 이 문제를 보고 생각해본 부분
BufferedReader를 사용하여 입력을 빠르게 읽는다.
첫 번째 줄에서 콘테스트 수 n을 입력받고, 두 번째 줄에서 상금 정보를 입력받는다.
각 상금을 정수로 변환하여 총합을 계산해준다.
총합이 3으로 나누어 떨어지면 "yes"를 출력하고, 그렇지 않으면 "no"를 출력한다.
코드로 구현
package baekjoon.baekjoon_26;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// 백준 20332번 문제
public class Main917 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// 첫 번째 줄에서 콘테스트 수 입력
int n = Integer.parseInt(br.readLine());
// 두 번째 줄에서 상금 입력
String[] prizes = br.readLine().split(" ");
int totalPrize = 0;
// 상금의 총합 계산
for(int i = 0; i < n; i++) {
totalPrize += Integer.parseInt(prizes[i]);
}
// 총합이 3으로 나누어 떨어지는지 확인
if(totalPrize % 3 == 0) {
System.out.println("yes");
} else {
System.out.println("no");
}
br.close();
}
}
코드와 설명이 부족할수 있습니다. 코드를 보시고 문제가 있거나 코드 개선이 필요한 부분이 있다면 댓글로 말해주시면 감사한 마음으로 참고해 코드를 수정 하겠습니다.