ALGORITHM/BOJ

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

0298 2021. 11. 8. 00:57

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

 

2941번: 크로아티아 알파벳

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

www.acmicpc.net

2021-11-07


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
public class Main {
    public static String[] arr = {"c=""c-""dz=""d-""lj""nj""s=""z="};
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(bf.readLine());
 
        String str = st.nextToken();
        for (String s : arr) {
            if (str.contains(s)) str = str.replaceAll(s, "X");
        }
        System.out.println(str.length());
    }
}
cs

 

#문제풀이

replace를 사용하여 푸는 방법도 있을 것이고, 그냥 문자 하나하나 체크하는 방법도 있을 것이다

이 문제랑 좀 비슷하다는 생각을 했다.

 

https://void2017.tistory.com/259

 

[프로그래머스] 숫자 문자열과 영단어 (2021 카카오 채용연계형 인턴십)

https://programmers.co.kr/learn/courses/30/lessons/81301 코딩테스트 연습 - 숫자 문자열과 영단어 네오와 프로도가 숫자놀이를 하고 있습니다. 네오가 프로도에게 숫자를 건넬 때 일부 자릿수를 영단어로 바

void2017.tistory.com