• 문제 링크
https://www.acmicpc.net/problem/24936
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Set;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
int n = read(), sum = 0;
int[] arr = new int[n];
while (n-- > 0) sum += arr[n] = read();
Set<Integer> set = new TreeSet<>();
for (int i : arr) set.add(sum - i);
sb.append(set.size()).append("\n");
for (int i : set) sb.append(i).append(" ");
bw.write(sb.toString());
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' 카테고리의 다른 글
[백준] 2669 직사각형 네개의 합집합의 면적 구하기 - Implementation / Java (0) | 2024.06.28 |
---|---|
[백준] 2331 반복수열 - Implementation / Java (0) | 2024.06.27 |
[백준] 11518 Morse - Data Structure / Java (0) | 2024.06.25 |
[백준] 15088 Game of Throwns - Data Structure / Java (0) | 2024.06.24 |
[백준] 23544 Kinder Surprise - Data Structure / Java (0) | 2024.06.23 |
댓글