• Home

My Codegate

  • Home

백준 1343 폴리오미노 자바 문제풀이

2023/12/05 Posted by Codegate Java No Comments
백준 1343 폴리오미노 자바 문제풀이

문제 링크

X와 .으로 이루어진 값을 입력으로 받아 XXXX는 AAAA로 치환하고, XX는 BB로 치환해서 치환한 결과를 출력하고, 만약 X가 남아있을 경우에는 -1을 출력해주면 되는데

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

public class Polyomino {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine().replaceAll("XXXX", "AAAA");
        String s1 = s.replaceAll("XX", "BB");
        int x = s1.indexOf("X");
        if(x != -1) {
            System.out.println(-1);
        } else {
            System.out.println(s1);
        }
    }
}

풀이는 먼저 XXXX를 AAAA로 치환한 뒤 XX를 BB로 모두 치환해주고, 치환 작업이 끝난 후 X가 남아있다면 -1을, 그렇지 않다면 치환한 값을 반환해주면 끝이다.

No Comments
0

Leave a Reply Cancel Reply

Introduction

My Codegate

Latest Posts

  • Google Search Console API 연동방법
  • 인텔리제이 Gradle Dependency 최신 버전 보는 방법
  • Wallet-Tracker 개발일지
  • Moralis API 자바로 호출방법
  • IntelliJ Commit 후 Push 따로 하는 방법

Categories

  • My Project (4)
  • Java (42)
  • Algorithm (161)
    • Java (152)
    • Algorithm Knowledge (3)
    • Algorithm site usage (6)
  • Vue.js (1)
  • Spring (4)
  • Docker (2)
  • IntelliJ (20)
  • Uncategorized (7)

Recent Comments

  • Codegate on Hello world!
  • A WordPress Commenter on Hello world!

© 2025 — mycodegate.com

Prev Next