-
[Baekjoon Online Judge] 2941번: 크로아티아 알파벳문제 풀이/Baekjoon Online Judge 2021. 1. 5. 23:21
import java.io.*; import java.util.ArrayList; import java.util.List; public class Baekjoon2941 { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out)); List<String> croatiaAlphabetList = new ArrayList<>(); croatiaAlphabetList.add("c="); croatiaAlphabetList.add("c-"); croatiaAlphabetList.add("dz="); croatiaAlphabetList.add("d-"); croatiaAlphabetList.add("lj"); croatiaAlphabetList.add("nj"); croatiaAlphabetList.add("s="); croatiaAlphabetList.add("z="); String word = bufferedReader.readLine(); for (String croatiaAlphabet : croatiaAlphabetList) { if (word.contains(croatiaAlphabet)) word = word.replaceAll(croatiaAlphabet, " "); } bufferedWriter.write(String.valueOf(word.length())); bufferedWriter.flush(); bufferedReader.close(); bufferedWriter.close(); } }
replaceAll을 활용하여 크로아티아 알파벳이 나오면 공백으로 바꿔주고, 마지막에 해당 word의 길이를 출력한다.
'문제 풀이 > Baekjoon Online Judge' 카테고리의 다른 글
[Baekjoon Online Judge] 10773번: 제로 (0) 2021.01.08 [Baekjoon Online Judge] 10953번: A+B - 6 (0) 2021.01.08 [Baekjoon Online Judge] 1316번: 그룹 단어 체커 (0) 2021.01.05 [Baekjoon Online Judge] 11719번: 괄호 - 풀이 추가 예정 (0) 2021.01.05 [Baekjoon Online Judge] 11719번: 그대로 출력하기 2 (0) 2021.01.05