• 문제 링크
10643번: FUNGHI
Each of the eight lines of input contains the integer Si (0 ≤ Si ≤ 50, i = 1, 2, . . . , 8). These numbers are, respectively, the amount of mushrooms on pizza slices, where the slices are given in clockwise order.
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int[] arr = new int[8];
for (int i = 0; i < 8; i++) arr[i] = read();
int max = 0;
for (int i = 0; i < 8; i++) {
int sum = 0;
for (int j = i + 3; j >= i; j--) sum += arr[j % 8];
max = Math.max(max, sum);
}
bw.write(String.valueOf(max));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 2501 약수 구하기 - Brute Force / Java (0) | 2024.03.26 |
---|---|
[백준] 5618 공약수 - Brute Force / Java (0) | 2024.03.25 |
[백준] 1440 타임머신 - Brute Force / Java (0) | 2024.03.23 |
[백준] 8958 OX퀴즈 - Implementation / Java (0) | 2024.03.22 |
[백준] 2577 숫자의 개수 - Implementation / Java (0) | 2024.03.21 |
댓글