1+ package backjoon ;
2+
3+ import java .io .BufferedReader ;
4+ import java .io .IOException ;
5+ import java .io .InputStreamReader ;
6+ // https://www.acmicpc.net/problem/2941
7+ // 크로아티아 알파벳
8+ public class _2941 {
9+
10+ public static void main (String [] args ) throws IOException {
11+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
12+ String word = br .readLine ();
13+ int cnt = 0 ;
14+
15+ // sol 첫방법실패
16+ // 이 접근법은 replace되고 남은 뒷부분 알파벳뿐만아니라 이미 지나간 알파벳과 함께 크로아티아 알파벳인지 체크하기때문에 오류가 발생함
17+ /*
18+ String[] croatiaAlpha = new String[]{"c=", "c-","dz=", "d-", "lj", "nj", "s=", "z="};
19+
20+ for(int i=0; i<croatiaAlpha.length; i++){
21+ if(word.contains(croatiaAlpha[i])){
22+ cnt++;
23+ word = word.replace(croatiaAlpha[i], "");
24+ }
25+ }
26+ cnt = cnt + word.length();
27+ */
28+
29+ // sol2 memory 11484 runtime 80
30+ int len = word .length ();
31+ for (int i = 0 ; i < len ; i ++) {
32+
33+ char alphabet = word .charAt (i );
34+ if (alphabet == 'c' && i < len - 1 ) {
35+ if (word .charAt (i + 1 ) == '=' || word .charAt (i + 1 ) == '-' ) {
36+ i ++;
37+ }
38+ }
39+ else if (alphabet == 'd' && i < len - 1 ) {
40+ if (word .charAt (i + 1 ) == '-' ) {
41+ i ++; //d-인 경우 조건문의 word길이에서 1를 빼줘야한다
42+ }
43+ else if (word .charAt (i + 1 ) == 'z' && i < len - 2 ) {
44+ if (word .charAt (i + 2 ) == '=' ) {
45+ i += 2 ; //dz-인경우 조건문의 word길이에서 2를 빼줘야한다
46+ }
47+ }
48+ }
49+ else if ((alphabet == 'l' || alphabet == 'n' ) && i < len - 1 ) {
50+ if (word .charAt (i + 1 ) == 'j' ) {
51+ i ++;
52+ }
53+ }
54+ else if ((alphabet == 's' || alphabet == 'z' ) && i < len - 1 ) {
55+ if (word .charAt (i + 1 ) == '=' ) {
56+ i ++;
57+ }
58+ }
59+ cnt ++;
60+ }
61+ System .out .println (cnt );
62+ }
63+ }
64+ /*
65+ input
66+ nljj
67+
68+ output
69+ 3
70+
71+ input
72+ c=c=
73+
74+ output
75+ 2
76+ */
0 commit comments