• 문제 링크
https://www.acmicpc.net/problem/2774
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashSet;
import java.util.Set;
public class Main {
static Set<Integer> set = new HashSet<>();
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
int t = read();
while (t-- > 0) sb.append(calc(read())).append('\n');
bw.write(sb.toString());
bw.flush();
}
private static int calc(int n) {
set.clear();
do set.add(n % 10); while ((n /= 10) > 0);
return set.size();
}
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' 카테고리의 다른 글
[백준] 5523 경기 결과 - Implementation / Java (0) | 2025.03.13 |
---|---|
[백준] 5613 계산기 프로그램 - Implementation / Java (0) | 2025.03.12 |
[백준] 3062 수 뒤집기 - Implementation / Java (0) | 2025.03.10 |
[백준] 2783 삼각 김밥 - Implementation / Java (0) | 2025.03.09 |
[백준] 13280 Selection of Participants of an Experiment - Brute Force / Java (0) | 2025.03.08 |
댓글