본문 바로가기
Problem Solving/Baekjoon

[백준] 26753 OIJ - Greedy / Java

by graycode 2025. 8. 27.

 문제 링크

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

 

 풀이 코드

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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        char[] arr = {'o', 'i', 'j'};
        int c, i = 0, cnt = 0;
        while ((c = System.in.read()) > 13) {
            if (arr[i] == c && ++i == 3) {
                i = 0;
                cnt++;
            }
        }

        bw.write(cnt > 0 ? String.valueOf(cnt) : "NIE");
        bw.flush();
    }

}

댓글