[백준] JAVA/문자열

[백준] JAVA 2941: 크로아티아 알파벳

코딩하는곰곰 2021. 12. 8. 22:15

https://www.acmicpc.net/problem/2941

 

2941번: 크로아티아 알파벳

예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다. 크로아티아 알파벳 변경 č c= ć c- dž dz= đ d- lj lj nj nj š s= ž z=

www.acmicpc.net


Solution1:

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));
		String str = br.readLine();
		int cnt = 0;
		
		for(int i=0;i<str.length();i++) {
			//'='또는'-'를 포함한 크로아티아 알파벳일 경우
			if(str.charAt(i)=='=') {
				if(str.charAt(i-1)=='z'&&i>1) {
					if(str.charAt(i-2)=='d') {
						cnt++;
					}
				}
				cnt++;
			}
			else if(str.charAt(i)=='-') {
				cnt++;
			}
			else if(str.charAt(i)=='j'&&i>0) {
				if(str.charAt(i-1)=='l'||str.charAt(i-1)=='n') {
					cnt++;
				}
			}
		}
		
		System.out.print(str.length()-cnt);
	}
}