백준1316: 그룹 단어 체커
문제
https://www.acmicpc.net/problem/1316
문제 풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int cnt = 0;
for (int i = 0; i < n; i++) {
if (check(sc.next())) {
cnt++;
}
}
System.out.println(cnt);
}
public static boolean check(String word) {
boolean[] alphabet = new boolean[26];
int prev = 0;
for (int i = 0; i < word.length(); i++) {
int now = word.charAt(i);
if (prev != now) {
if (!alphabet[now - 'a']) {
alphabet[now - 'a'] = true;
prev = now;
} else {
return false;
}
}
}
return true;
}
}
댓글남기기