

이것도 이전 크로아티아 알파벳과 함께, 제 골머리 좀 썩혔습니다. 이어지는지 끊어지는지에 대한 판단을 어떻게 하게 할것이냐, 그게 제일 고민이었어요. 단순히 앞뒤 비교로 퉁치기엔, 이어지는 연속된 숫자는 해당 안 될 수 있고,
aba처럼 바로 옆에 오는 것이면 몰라도, asddgsga 처럼 한참 후에야 중복되는 경우도 있으니까요.
결국 알파벳에 대응되는 배열로 만들어서, 각 알파벳이 다시 나올때마다 해당되는 위치의 배열의 카운트를 늘리는 방식으로 해결했습니다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int count = n;
String str;
for (int i=0; i<n; i++) {
str = br.readLine();
int[] mtcount = new int[26]; // 중복숫자 카운트
mtcount[str.charAt(0)-97]++;
for (int j=0; j<str.length()-1; j++) {
if (str.charAt(j) != str.charAt(j+1)) {
mtcount[str.charAt(j+1)-97]++;
}
}
for (int k=0; k<26; k++) {
if (mtcount[k]>=2) {
count--;
break;
}
}
}
System.out.println(count);
}
}'백준 문제풀이 > 문자열' 카테고리의 다른 글
| 2941. 크로아티아 알파벳 (자바, Java) (0) | 2022.09.13 |
|---|---|
| 5622. 다이얼 (자바, Java) (0) | 2022.09.13 |
| 2908. 상수 (자바, JAVA) (0) | 2022.09.13 |
| 1152. 단어의 개수 (자바, Java) (0) | 2022.09.13 |
| 1157. 단어 공부 (자바, JAVA) (0) | 2022.09.13 |