728x90
https://swexpertacademy.com/main/solvingProblem/solvingProblem.do
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
String 사용
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 1; tc <= t; tc++) {
boolean isExist[] = new boolean[10];
String str = sc.next();
int count = 0;
for (int i = 0; i < str.length(); i++) {
if (!isExist[str.charAt(i)-'0']) {
count++;
isExist[str.charAt(i) - '0'] = true;
}
}
System.out.println("#" + tc + " " + count);
}
}
}
int 사용
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 1; tc <= t; tc++) {
boolean isExist[] = new boolean[10];
int n = sc.nextInt();
int count = 0;
while (n > 0) {
if (!isExist[n % 10]) {
count++;
isExist[n % 10] = true;
}
n /= 10;
}
System.out.println("#" + tc + " " + count);
}
}
}
728x90
'SW Expert Academy > SWEA D3' 카테고리의 다른 글
| [SW Expert Academy] 코딩 토너먼트1 (D3) (0) | 2024.08.31 |
|---|---|
| [SW Expert Academy] [S/W 문제해결 기본] 3일차 - 회문1 (0) | 2024.08.29 |
| [SW Expert Academy] 민석이의 과제 체크하기 (D3) (0) | 2024.08.29 |
| [SW Expert Academy] Summation (D3) (0) | 2024.08.29 |
| [SW Expert Academy] [Professional] 쥬스 나누기 (D3) (0) | 2024.08.29 |