๐ŸŒžAlgorithm/๐Ÿ”ฅBaekjoon

[Baekjoon] 2671_์ž ์ˆ˜ํ•จ์‹๋ณ„

๋ฟŒ์•ผ._. 2024. 8. 30. 13:56
๋ฌธ์ œ(์ถœ์ฒ˜: https://www.acmicpc.net/problem/2671)

< ์ž ์ˆ˜ํ•จ์‹๋ณ„ >

 

๋ฌธ์ œ ํ’€์ด 

 

๋ฌธ์ œ์—์„œ ~๋Š” ํ•œ๋ฒˆ ์ด์ƒ ๋ฐ˜๋ณต๋˜๋Š” ๊ฒƒ์ด๋ฏ€๋กœ ์ •๊ทœ์‹์—์„œ๋Š” +๋กœ ์‚ฌ์šฉํ•œ๋‹ค. ํŒจํ„ด (100+1+|01)+์™€ ์ผ์น˜ํ•˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

 

 my solution (Java)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

public class _2671_ { // ์ž ์ˆ˜ํ•จ์‹๋ณ„

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

		String str = bf.readLine();
		if (Pattern.matches("(100+1+|01)+", str)) {
			System.out.println("SUBMARINE");
		} else {
			System.out.println("NOISE");
		}
	}
}
๋ณ€์ˆ˜)
str : ๋ฌธ์ž์—ด

 

๋ฌธ์ž์—ด์„ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. ์ •๊ทœํ‘œํ˜„์‹ (100+1+|01)+์™€ ์ผ์น˜ํ•˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.