백준 문제풀이/문자열

1316. 그룹 단어 체커 (자바, Java)

뮤츠 2022. 9. 13. 02:53

이것도 이전 크로아티아 알파벳과 함께, 제 골머리 좀 썩혔습니다. 이어지는지 끊어지는지에 대한 판단을 어떻게 하게 할것이냐, 그게 제일 고민이었어요. 단순히 앞뒤 비교로 퉁치기엔, 이어지는 연속된 숫자는 해당 안 될 수 있고,

aba처럼 바로 옆에 오는 것이면 몰라도, asddgsga 처럼 한참 후에야 중복되는 경우도 있으니까요.

결국 알파벳에 대응되는 배열로 만들어서, 각 알파벳이 다시 나올때마다 해당되는 위치의 배열의 카운트를 늘리는 방식으로 해결했습니다.

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int count = n;
		String str;
		
		
		for (int i=0; i<n; i++) {
			
			str = br.readLine();
			int[] mtcount = new int[26]; // 중복숫자 카운트
			
			mtcount[str.charAt(0)-97]++;
			
			for (int j=0; j<str.length()-1; j++) {
				
				if (str.charAt(j) != str.charAt(j+1)) {
					
					mtcount[str.charAt(j+1)-97]++;
					
				}
				
			}
			
			for (int k=0; k<26; k++) {
				
				
				if (mtcount[k]>=2) {
					
					count--;
					break;
					
				}				
			}			
		}
		
		
		System.out.println(count);
		
		

	}

}