From e155e458f5687c55f115bd787497cf6aa3223543 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sun, 10 Aug 2025 22:15:56 +0900 Subject: [PATCH] =?UTF-8?q?[20250810]=20BOJ=20/=20G4=20/=20A=EB=A5=BC=20B?= =?UTF-8?q?=EB=A1=9C=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../10 BOJ A\353\245\274 B\353\241\234.md" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "0224LJH/202508/10 BOJ A\353\245\274 B\353\241\234.md" diff --git "a/0224LJH/202508/10 BOJ A\353\245\274 B\353\241\234.md" "b/0224LJH/202508/10 BOJ A\353\245\274 B\353\241\234.md" new file mode 100644 index 00000000..123e56f5 --- /dev/null +++ "b/0224LJH/202508/10 BOJ A\353\245\274 B\353\241\234.md" @@ -0,0 +1,70 @@ +```java +import java.awt.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; +import java.util.List; + + +public class Main { + static String target,goal; + + static int size,ans; + static int[] arr; + + static List list = new ArrayList<>(); + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + private static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + target = br.readLine(); + goal = br.readLine(); + ans = 0; + } + + private static void process() throws IOException { + + int goalIdx = goal.length()-1; + + for (int i = target.length()-1; i >= 0; i--) { + if (target.charAt(i) == goal.charAt(goalIdx)) { + goalIdx--; + } else { + list.add(target.charAt(i)); + ans++; + } + } + + if (goalIdx == -1) return; + + Outer: + while (goalIdx >= 0) { + for (int i = 0; i < list.size(); i++) { + Character c = list.get(i); + if (c==goal.charAt(goalIdx)) { + goalIdx--; + list.remove(i); + continue Outer; + } + } + + goalIdx--; + + } + + if (list.size() != 0) ans = -1; + + } + + + private static void print() { + System.out.println(ans); + } +} +``` \ No newline at end of file