알고리즘/백준

백준 2941 크로아티아 알파벳 자바

reumiii 2019. 10. 23. 21:08
import java.util.*;
public class Main{
	public static void main(String[] args) {
		/*
		 * 첫째 줄에 최대 100글자의 단어가 주어진다. 알파벳 소문자와 '-', '='로만 이루어져 있다. 단어는 크로아티아 알파벳으로 이루어져
		 * 있다. 문제 설명의 표에 나와있는 알파벳은 변경된 형태로 입력된다.
		 */
		Scanner sc = new Scanner(System.in);
		String str = sc.next(); // 입력으로 주어진 단어
		int result = 0;

		for (int i = 0; i < str.length(); i++) {
			char ch = str.charAt(i);

			if (i < str.length() - 1) {
				char nextCh = str.charAt(i + 1); // 다음 글자

				switch (ch) { // 크로아티아 알파벳이면 그 다음 글자로 이동
				case 'c':
					if (nextCh == '=' || nextCh == '-') {
						i++;
					}
					break;
				case 'd':
					if (nextCh == 'z') {
						if (i + 2 < str.length() && str.charAt(i + 2) == '=') { // 다다음 글자가 존재하는지도 확인해야함
							i += 2;
						}
					} else if (nextCh == '-') {
						i++;
					}
					break;
				case 'l':
					if (nextCh == 'j') {
						i++;
					}
					break;
				case 'n':
					if (nextCh == 'j') {
						i++;
					}
					break;
				case 's':
					if (nextCh == '=') {
						i++;
					}
					break;
				case 'z':
					if (nextCh == '=') {
						i++;
					}
					break;
				}

			}

			result += 1;
		}

		System.out.println(result);
	}
}