1316 백준 – java


생각보다 조금 쉬웠던 문제

처음에 좀 어렵게 느껴졌어요

부울 값을 사용하십시오.

이 알파벳을 처음 사용하는 경우 true로 설정하십시오.

처음 사용한 알파벳이 아니고 이전 알파벳과 같은 알파벳이 아닌 경우

잘못된 베팅이며 참인 경우에만 계산됩니다.

import java.util.Scanner;

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++) {
            String word = sc.next(); 
            boolean() apl = new boolean(26); 
            boolean check = true;
            for (int j = 0; j < word.length(); j++) {
                char c = word.charAt(j);
                if (!apl(c - 'a')) { 
                    apl(c - 'a') = true;
                } else { 
                    if (word.charAt(j - 1) != c) { 
                        check = false;
                        break;
                    }
                }
            }
            if (check) {
                cnt++;
            }
        }

        System.out.println(cnt); 
}
}