Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
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
Tags
more
Archives
Today
Total
관리 메뉴

main

[백준-1316번/Java] 그룹 단어 체커 본문

Algorithm

[백준-1316번/Java] 그룹 단어 체커

1984 2022. 11. 11. 14:07
import java.util.*;
import java.io.*;

public class Main {

	private static int groupWordChecker(String str) {
		char memory = '0';
		int[] alphabets = new int['z' - 'a' + 1];

		for (int j = 0; j < alphabets.length; j++) {
			alphabets[j] = 0;
		}

		for (char c : str.toCharArray()) {
			if (memory == c) {
				continue;
			} else if (alphabets[c - 'a'] == 0) {
				alphabets[c - 'a'] = 1;
				memory = c;
				continue;
			} else if (alphabets[c - 'a'] == 1) {
				return 0;
			}
		}

		return 1;
	}

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.nextLine());

		int count = 0;

		for (int i = 0; i < N; i++) {
			String str = sc.nextLine();
			count += groupWordChecker(str);
		}

		System.out.println(count);

		sc.close();

	}

}
728x90
Comments