From 98a60439bba100d9dd89873c0ae5733d39159598 Mon Sep 17 00:00:00 2001 From: "YeJun, Jung" <31740224+yejun614@users.noreply.github.com> Date: Wed, 28 Jan 2026 17:06:07 +0900 Subject: [PATCH] feat: add p1289 solutions --- problems/SWEA/p1289/Solution.java | 60 ++++++++++++++++++++++++++++++ problems/SWEA/p1289/Solution2.java | 32 ++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 problems/SWEA/p1289/Solution.java create mode 100644 problems/SWEA/p1289/Solution2.java diff --git a/problems/SWEA/p1289/Solution.java b/problems/SWEA/p1289/Solution.java new file mode 100644 index 0000000..7fee21a --- /dev/null +++ b/problems/SWEA/p1289/Solution.java @@ -0,0 +1,60 @@ +package p1289; + +import java.util.Scanner; + +public class Solution { + static Scanner scanner; + + public static void main(String[] args) { + scanner = new Scanner(System.in); + + int testCount = scanner.nextInt(); + scanner.nextLine(); + + for (int testCase = 1; testCase <= testCount; testCase++) { + Solution solution = new Solution(testCase); + solution.run(); + } + + scanner.close(); + } + + int testCase; + int answer; + String goalMem; + + public Solution(int testCase) { + this.testCase = testCase; + } + + public void run() { + input(); + solve(); + print(); + } + + private void print() { + System.out.printf("#%d %d\n", testCase, answer); + } + + private void solve() { + answer = 0; + + // 앞에서 부터 목표 값이랑 비교하면서 덮어씌운다 + // 이미 목표 값이랑 동일하면 설정안하고 그냥 다음으로 커서를 넘긴다. + + final int memSize = goalMem.length(); + char filled = '0'; + + for (int cursor = 0; cursor < memSize; cursor++) { + if (goalMem.charAt(cursor) != filled) { + answer++; + filled = filled == '0' ? '1' : '0'; + } + } + } + + private void input() { + goalMem = scanner.nextLine().trim(); + } +} diff --git a/problems/SWEA/p1289/Solution2.java b/problems/SWEA/p1289/Solution2.java new file mode 100644 index 0000000..cce8ea6 --- /dev/null +++ b/problems/SWEA/p1289/Solution2.java @@ -0,0 +1,32 @@ +package p1289; + +import java.io.BufferedReader; +import java.io.InputStreamReader; + +public class Solution2 { + public static void main(String[] args) throws Exception { + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + StringBuilder output = new StringBuilder(); + + int testCount = Integer.parseInt(reader.readLine().trim()); + + for (int testCase = 1; testCase <= testCount; testCase++) { + int answer = 0; + + String goalMem = reader.readLine().trim(); + final int memSize = goalMem.length(); + char filled = '0'; + + for (int cursor = 0; cursor < memSize; cursor++) { + if (goalMem.charAt(cursor) != filled) { + answer++; + filled = filled == '0' ? '1' : '0'; + } + } + + output.append(String.format("#%d %d\n", testCase, answer)); + } + + System.out.print(output.toString()); + } +}