• 문제 링크
28323번: 불안정한 수열
$N$개의 자연수가 좌우 일렬로 놓여 있다. 왼쪽에서 $i$ ($1 \le i \le N$)번째에 놓여 있는 자연수는 $A_i$다. 여러분은 이 중 몇 개의 자연수를 원하는 만큼 고를 수 있다. 단, 아무 자연수도 고르지 않
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(), k = n;
int[] arr = new int[n];
arr[0] = read();
for (int i = 1; i < n; i++) if ((arr[i - 1] + (arr[i] = read())) % 2 == 0) k--;
bw.write(String.valueOf(k));
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' 카테고리의 다른 글
[백준] 20974 Even More Odd Photos - Greedy / Java (0) | 2023.12.20 |
---|---|
[백준] 15761 Lemonade Line - Greedy / Java (0) | 2023.12.19 |
[백준] 4993 Red and Black - Graph Theory / Java (0) | 2023.12.17 |
[백준] 15242 Knight - Graph Theory / Java (0) | 2023.12.16 |
[백준] 6207 Cow Picnic - Graph Theory / Java (0) | 2023.12.15 |
댓글