BOJ 1316 그룹 단어 체커

Jmnote (토론 | 기여)님의 2018년 7월 14일 (토) 08:40 판 (새 문서: 분류: BOJ 7단계 ==개요== * {{BOJ|1316}} * 알고리즘 분류: 문자열 처리, 탐색 ==Java== 분류: BOJ Java <source lang='java'> import java.util.Scanner; public...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

BOJ 1316 그룹 단어 체커

[[분류:BOJ {{{단계}}}단계]]

  • 알고리즘 분류: 문자열 처리, 탐색

2 Java

import java.util.Scanner;
public class Main {
    private static boolean isGroupWord(String word) {
        for(int i=0; i<word.length(); i++) {
            char a = word.charAt(i);
            //System.out.println(a);
            boolean continuos = true;
            for(int j=i+1; j<word.length(); j++) {
                char b = word.charAt(j);
                //System.out.print(a + "-" + b + " ");
                //System.out.println(continuos);
                if( a == b ) {
                    if( !continuos ) return false;
                    i++;
                }
                else {
                    continuos = false;
                }
            }
        }
        return true;
    }
    public static void main(String args[]) {
        /*
        System.out.println( isGroupWord("ccazzzzbb") );
        System.out.println( isGroupWord("kin") );
        System.out.println( isGroupWord("aabbbccb") ); // false
        
        System.out.println( isGroupWord("happy") );
        System.out.println( isGroupWord("new") );
        System.out.println( isGroupWord("year") );

        System.out.println( isGroupWord("aba") ); // false
        System.out.println( isGroupWord("abab") ); // false
        System.out.println( isGroupWord("abcabc") ); // false
        System.out.println( isGroupWord("a") );
        */
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        for( int i=0; i<n; i++ ) {
            String word = sc.next();
            if( isGroupWord(word) ) count++;
        }
        System.out.println( count );
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}