main
[백준-1316번/Java] 그룹 단어 체커 본문
import java.util.*;
import java.io.*;
public class Main {
private static int groupWordChecker(String str) {
char memory = '0';
int[] alphabets = new int['z' - 'a' + 1];
for (int j = 0; j < alphabets.length; j++) {
alphabets[j] = 0;
}
for (char c : str.toCharArray()) {
if (memory == c) {
continue;
} else if (alphabets[c - 'a'] == 0) {
alphabets[c - 'a'] = 1;
memory = c;
continue;
} else if (alphabets[c - 'a'] == 1) {
return 0;
}
}
return 1;
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int N = Integer.parseInt(sc.nextLine());
int count = 0;
for (int i = 0; i < N; i++) {
String str = sc.nextLine();
count += groupWordChecker(str);
}
System.out.println(count);
sc.close();
}
}
728x90
'Algorithm' 카테고리의 다른 글
[백준-10988번/Java] 팰린드롬인지 확인하기 (0) | 2022.11.11 |
---|---|
[백준-4963번/Java] 섬의 개수 (0) | 2022.11.11 |
[백준-5622번/Java] 다이얼 (0) | 2022.11.11 |
[백준-1920번/Java] 수 찾기 (0) | 2022.11.11 |
[백준-2839번/Java] 설탕배달 (0) | 2022.11.11 |