[SWEA] 다양성 측정

문제 보러가기

제한사항

이외의 제한사항은 없다.

첫번째 생각

숫자배열을 두어 true, false로 관리한다.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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[] check = new boolean[10];
			String s = sc.next();
			for(int i=0; i<s.length(); i++) {
				check[s.charAt(i)-'0'] = true;
			}
			int ans = 0 ;
			for(int i=0; i<10; i++) {
				if ( check[i] ) { 
					ans++;
				}
			}
			System.out.println("#"+tc+" "+ans);
		}
	}
}