• 문제 링크
https://www.acmicpc.net/problem/15234
• 풀이 코드
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 = read();
int[] arr = new int[n];
while (n-- > 0) arr[n] = read();
for (int i = 0; i < arr.length; i++) for (int j = i + 1; j < arr.length; j++) if (arr[i] + arr[j] == k) n++;
bw.write(String.valueOf(n + 1));
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' 카테고리의 다른 글
[백준] 4391 Y2K Accounting Bug - Backtracking / Java (0) | 2024.09.07 |
---|---|
[백준] 22970 문제 재탕 - Brute Force / Java (0) | 2024.09.06 |
[백준] 9229 단어 사다리 - Brute Force / Java (0) | 2024.09.04 |
[백준] 6751 From 1987 to 2013 - Brute Force / Java (0) | 2024.09.03 |
[백준] 11116 교통량 - Brute Force / Java (0) | 2024.09.02 |
댓글