알고리즘 풀이/백준

[백준][Java] 2941번 크로아티아 알파벳

배게 2021. 6. 26. 23:51
728x90

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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
 
 
public class Main {
        
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    
    public static void main(String[] args) throws IOException{
        // 크로아티아 문자를 알파벳이  아닌 특수한 문자 하나로 치환해줌.
        // 그리고 그 result String의 길이값을 반환해줌.
        String input = br.readLine();
        
        String[] croatiaAlphabet = {"c=","c-","dz=","d-","lj","nj","s=","z="};
        
        for(int i=0; i<croatiaAlphabet.length; i++) {
            input = input.replaceAll(croatiaAlphabet[i], "*");
        }
        System.out.println(input.length());
        
    }
}
cs