1316

qkrrnjswo·2023년 4월 21일
0

백준, 프로그래머스

목록 보기
22/53

1. 그룹 단어 체커

		Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int count = 0;

        for (int i = 0; i < n; i++) {
            boolean[] alphabet = new boolean[26];
            String word = scanner.next();
            char[] words = word.toCharArray();

            if (words.length == 1) {count++;}
            else {
                alphabet[words[0]-'a'] = true;

                for (int j = 1; j < words.length; j++) {
                    if (words[j] != words[j - 1]) {
                        if (alphabet[words[j] - 'a']) {
                            break;
                        } else {
                            alphabet[words[j] - 'a'] = true;
                        }
                    }

                    if (j == words.length - 1) count++;
                }
            }
        }

0개의 댓글