Algorithm
[백준-1316번/Java] 그룹 단어 체커
1984
2022. 11. 11. 14:07
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