πŸ—οΈ Algorithm/🟩 λ°±μ€€

🟩 [λ°±μ€€] [Java] [Silver5] 2941번_ν¬λ‘œμ•„ν‹°μ•„ μ•ŒνŒŒλ²³

Dbswnstjd 2023. 12. 10. 20:21

문제

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

 

2941번: ν¬λ‘œμ•„ν‹°μ•„ μ•ŒνŒŒλ²³

μ˜ˆμ „μ—λŠ” μš΄μ˜μ²΄μ œμ—μ„œ ν¬λ‘œμ•„ν‹°μ•„ μ•ŒνŒŒλ²³μ„ μž…λ ₯ν•  μˆ˜κ°€ μ—†μ—ˆλ‹€. λ”°λΌμ„œ, λ‹€μŒκ³Ό 같이 ν¬λ‘œμ•„ν‹°μ•„ μ•ŒνŒŒλ²³μ„ λ³€κ²½ν•΄μ„œ μž…λ ₯ν–ˆλ‹€. ν¬λ‘œμ•„ν‹°μ•„ μ•ŒνŒŒλ²³ λ³€κ²½ č c= Δ‡ c- dΕΎ dz= Δ‘ d- lj lj nj nj š s= ΕΎ z=

www.acmicpc.net

풀이

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

public class ν¬λ‘œμ•„ν‹°μ•„μ•ŒνŒŒλ²³ {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        byte[] byteArr = br.readLine().getBytes();
        int count = 0;

        for (int i = 0; i < byteArr.length; i++) {
            if (byteArr[i] == 'c' && i < byteArr.length - 1) {
                if (byteArr[i + 1] == '=' || byteArr[i + 1] == '-') {
                    i++;
                }
            } else if (byteArr[i] == 'd' && i < byteArr.length - 1) {
                if (byteArr[i + 1] == 'z' && i < byteArr.length - 2) {
                    if (byteArr[i + 2] == '=') {
                        i += 2;
                    }
                } else if (byteArr[i + 1] == '-') {
                    i++;
                }
            } else if (byteArr[i] == 'l' && i < byteArr.length - 1) {
                if (byteArr[i + 1] == 'j') {
                    i++;
                }
            } else if (byteArr[i] == 'n' && i < byteArr.length - 1) {
                if (byteArr[i + 1] == 'j') {
                    i++;
                }
            } else if (byteArr[i] == 's' && i < byteArr.length - 1) {
                if (byteArr[i + 1] == '=') {
                    i++;
                }
            } else if (byteArr[i] == 'z' && i < byteArr.length - 1) {
                if (byteArr[i + 1] == '=') {
                    i++;
                }
            }
            count++;
        }
        System.out.println(count);
    }
}

λ¬Έμ œλŠ” λ‹¨μˆœνžˆ 경우의 수만 잘 λ‚˜λˆ„κ³  λ°°μ—΄μ˜ 크기만 μ£Όμ˜ν•΄μ£Όλ©΄ λœλ‹€.