Hope Everyone Is Happy

[실버5] 2941. 크로아티아 알파벳 (Java) 본문

※ 백준 (Baekjoon)/[Java] 문제 풀이 ( Solve the problems)

[실버5] 2941. 크로아티아 알파벳 (Java)

J 크 2023. 8. 27. 11:21
728x90
반응형

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

 

2941번: 크로아티아 알파벳

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

www.acmicpc.net

IM, A형 테스트 화이팅입니다~!!


※  문제를 요약하면 아래와 같습니다.

  크로아티아 알파벳 6개가 아래와 같이 영어로 변형하여 존재

단어가 입력 되었을 때, 위에 해당되는 알파벳 들은 하나로 카운트하여 단어 내 총 알파벳(영어 포함) 갯수 출력

 Input : 첫줄에 최대 100글자의 단어가 알파벳 소문자와 '-', '='로만 이루어짐

 Output : 단어 내 알파벳 갯수 출력


◈ Input -1

ljes=njak

◈ Output-1

6

◈ Input -2

ddz=z=

◈ Output-2

3

◈ Input -3

nljj

◈ Output-3

3

◈ Input -4

c=c=

◈ Output-4

2

 ◎  코드 작성 전, 아래와 같이 솔루션을 정리하였습니다.

 크로아티아 알파벳들은 임의로 알파벳 'a'로 변경하여 길이를 읽을 때 1로 읽도록 변경

 변경 후 문자열 길이 출력


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bWriter = new BufferedWriter(new OutputStreamWriter(System.out));
	
		//StringTokenizer st = new StringTokenizer(bReader.readLine());
		
		String strAlphabets = bReader.readLine();
		
		String[] strCroatia = {"c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="};
		
		for(int i = 0 ; i < strCroatia.length; i++) {
			while(strAlphabets.contains(strCroatia[i])) {
				strAlphabets = strAlphabets.replace(strCroatia[i], "a");
			}
		}
		
		int nCount = strAlphabets.length();
		
		bWriter.write(String.valueOf(nCount));
		bWriter.flush();
		bWriter.close();
	}

}

읽어주셔서 감사합니다!

Good Luck! (피드백 감사합니다!)