알고리즘/백준

백준 1316 그룹 단어 체커 자바

reumiii 2019. 10. 24. 23:24
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); // 들어올 단어의 개수
		int result = 0; // 그룹 단어의 개수

		for (int i = 0; i < n; i++) {
			String word = sc.next();
			boolean check[] = new boolean[26];
			char pastCh = ' ';

			for (int j = 0; j < word.length(); j++) {
				if (pastCh != word.charAt(j)) {// 다른 알파벳이 나왔을때
					if (check[word.charAt(j) - 'a'] == true) {// 전에 나왔던 알파벳이면 그룹단어 아님.
						break;
					}
					check[word.charAt(j) - 'a'] = true;// 아직 나오지 않았던 알파벳이면 true 체크해주고 다음으로 넘김
				}
				
				pastCh = word.charAt(j);
				if(j==word.length()-1) {//마지막 알파벳까지 검토하여 ok이면 그룹단어의 개수 1 더함
					result++;
				}
			}
		}

		System.out.println(result);
    }
}