• 문제 링크
14720번: 우유 축제
영학이는 딸기우유, 초코우유, 바나나우유를 좋아한다. 입맛이 매우 까다로운 영학이는 자신만의 우유를 마시는 규칙이 있다. 맨 처음에는 딸기우유를 한 팩 마신다. 딸기우유를 한 팩 마신 후
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 n = read(), cnt = 0;
while (n-- > 0) if (read() == cnt % 3) cnt++;
bw.write(String.valueOf(cnt));
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' 카테고리의 다른 글
[백준] 16237 이삿짐센터 - Greedy / Java (0) | 2024.02.14 |
---|---|
[백준] 16200 해커톤 - Greedy / Java (0) | 2024.02.13 |
[백준] 27940 가지 산사태 - Greedy / Java (0) | 2024.02.11 |
[백준] 27563 Moo Operations - Greedy / Java (0) | 2024.02.10 |
[백준] 11255 ITAI Virus - Graph Theory / Java (0) | 2024.02.09 |
댓글