728x90
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
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++) {
int n = sc.nextInt();
HashSet<Character> set = new HashSet<>(); //중복 제거
int cnt = 0;
for (int i = 0; i < n; i++) {
set.add(sc.next().charAt(0));
}
ArrayList<Character> list = new ArrayList<>(set);
Collections.sort(list); //정렬하게 싫으면 위에서 Treeset쓰면 됨
for (int i = 0; i < list.size(); i++) {
if (list.get(i) != (char) ('A' + i)) { //아스키 코드로 비교
break;
}
cnt++;
}
System.out.println("#" + tc + " " + cnt);
}
}
}
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;
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++) {
int n = sc.nextInt();
TreeSet<Character> set = new TreeSet<>(); //중복 제거
int cnt = 0;
for (int i = 0; i < n; i++) {
set.add(sc.next().charAt(0));
}
ArrayList<Character> list = new ArrayList<>(set);
for (int i = 0; i < list.size(); i++) {
if (list.get(i) != (char) ('A' + i)) { //아스키 코드로 비교
break;
}
cnt++;
}
System.out.println("#" + tc + " " + cnt);
}
}
}728x90
'SW Expert Academy > SWEA D3' 카테고리의 다른 글
| [SW Expert Academy] 전봇대 (D3) (0) | 2024.09.20 |
|---|---|
| [SW Expert Academy] 이진수 표현 (D3) (0) | 2024.09.20 |
| [SW Expert Academy] 세상의 모든 팰린드롬 (D3) (0) | 2024.09.19 |
| [SW Expert Academy] 회문의 회문 (D3) (0) | 2024.09.19 |
| [SW Expert Academy] 팰린드롬 문제 (D3) (0) | 2024.09.19 |