๊ธฐ๋ก๋ฐฉ

BOJ_3447 : ๋ฒ„๊ทธ์™• ๋ณธ๋ฌธ

CodingTest/Java

BOJ_3447 : ๋ฒ„๊ทธ์™•

Soom_1n 2022. 12. 1. 16:39

๐Ÿ‘‰ ๋ฌธ์ œ๋งํฌ

 

3447๋ฒˆ: ๋ฒ„๊ทธ์™•

์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ ์ค„์˜ ์†Œ์Šค ์ฝ”๋“œ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ์ด ์†Œ์Šค ์ฝ”๋“œ๋Š” ๋ฐฑ์ค€์ด๊ฐ€ ์ž‘์„ฑํ•œ ๋ฒ„๊ทธ๋ฅผ ์ฐพ๋Š” ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ์ด๋ฏธ ์ฒ˜๋ฆฌ๊ฐ€ ๋˜์–ด์žˆ๋‹ค. ๊ฐ ์ค„์€ 100๊ธ€์ž ์ด๋‚ด์ด๊ณ , ์ž…๋ ฅ์€ ํŒŒ์ผ์ด ๋๋‚  ๋•Œ ๋๋‚œ๋‹ค. ์ค„์˜

www.acmicpc.net



๐Ÿ”ธ ๋ฌธ์ œ ๋ถ„์„ ๐Ÿ”ธ

  • EOF๊ฐ€ ์ž…๋ ฅ๋  ๋•Œ ๊นŒ์ง€ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅ๋ฐ›์•„ "BUG" ๋ฌธ์ž์—ด์ด ํฌํ•จ๋˜์ง€ ์•Š๋„๋ก ์ œ๊ฑฐํ•œ ๋’ค ์ถœ๋ ฅํ•œ๋‹ค.
    • "BUG"๋ฅผ ์ œ๊ฑฐํ•œ ๋’ค ๋‹ค์‹œ "BUG"๊ฐ€ ์ƒ๊ฒจ๋„ ์ œ๊ฑฐํ•ด์•ผํ•œ๋‹ค.

๐Ÿ”ธ ์ฝ”๋“œ ๐Ÿ”ธ

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = "";

        while ((input = br.readLine()) != null) {
            while (input.contains("BUG"))
                input = input.replaceAll("BUG", "");
            System.out.println(input);
        }
    }
}

๐Ÿ”ธ ์ฝ”๋“œ ํ•ด์„ ๐Ÿ”ธ

  • EOF๋ฅผ ๊ฐ์ง€ํ•˜๊ธฐ ์œ„ํ•ด br.readLine()์œผ๋กœ ํ•œ ์ค„์„ ์ž…๋ ฅ๋ฐ›๊ณ , ๊ทธ ๊ฐ’์ด null์ธ์ง€ ํ™•์ธํ•œ๋‹ค.
    • null์ด ์•„๋‹Œ ๋ฌธ์ž์—ด์—์„œ "BUG"๋ฌธ์ž์—ด์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ , ํฌํ•จ๋˜์ง€ ์•Š์„ ๋•Œ ๊นŒ์ง€ ๋ฐ˜๋ณตํ•ด์„œ ์ œ๊ฑฐํ•œ๋‹ค.

๐Ÿ”ธ end ๐Ÿ”ธ

  • EOF๋ฅผ ๊ฐ์ง€ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์œ„ ์ฝ”๋“œ์ฒ˜๋Ÿผ br.readLine()์„ ์“ฐ๋Š” ๋ฐฉ๋ฒ•๊ณผ Scanner์˜ has.next()๋ฅผ ์“ฐ๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค๋Š” ๊ฑธ ๋ฐฐ์› ๋‹ค.
  • replaceAll์€ replace์™€ ๋‹ฌ๋ฆฌ, ์ฐพ๋Š” ๋ฌธ์ž์—ด๋กœ ์ •๊ทœ ํ‘œํ˜„์‹์„ ๋„ฃ์„ ์ˆ˜ ์žˆ๋‹ค.

728x90

'CodingTest > Java' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

BOJ_3595 : ๋งฅ์ฃผ ๋ƒ‰์žฅ๊ณ   (0) 2022.12.05
BOJ_4158 : CD  (0) 2022.12.01
BOJ_2520 : ํŒฌ์ผ€์ดํฌ ์‚ฌ๋ž‘  (0) 2022.12.01
BOJ_2193 : ์ด์นœ์ˆ˜  (0) 2022.11.29
BOJ_13699 : ์ ํ™”์‹  (0) 2022.11.29