From 6ee55ab6a2f839d7eb4a591c26715533b959e5f4 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Thu, 13 Feb 2025 13:04:46 +0900 Subject: [PATCH] =?UTF-8?q?[20250213]=20BOJ=20/=20=EA=B3=A8=EB=93=9C4=20/?= =?UTF-8?q?=20=EB=AC=B8=EC=9E=90=EC=97=B4=20=EC=83=9D=EC=84=B1=20/=20?= =?UTF-8?q?=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\227\264 \354\203\235\354\204\261.md" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "Seol-JY/202502/13 BOJ G4 \353\254\270\354\236\220\354\227\264 \354\203\235\354\204\261.md" diff --git "a/Seol-JY/202502/13 BOJ G4 \353\254\270\354\236\220\354\227\264 \354\203\235\354\204\261.md" "b/Seol-JY/202502/13 BOJ G4 \353\254\270\354\236\220\354\227\264 \354\203\235\354\204\261.md" new file mode 100644 index 00000000..ab60ff52 --- /dev/null +++ "b/Seol-JY/202502/13 BOJ G4 \353\254\270\354\236\220\354\227\264 \354\203\235\354\204\261.md" @@ -0,0 +1,66 @@ +```java +import java.io.*; +import java.util.*; +public class Main { + private static int count = 0; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + int N = Integer.parseInt(br.readLine()); + + String[] arr = new String[N]; + for (int i = 0; i < N; i++) { + arr[i] = br.readLine(); + } + + int a = 0; + int b = N - 1; + while (a <= b) { + if (arr[a].compareTo(arr[b]) > 0) { + write(bw, arr[b]); + b--; + } else if(arr[a].compareTo(arr[b]) == 0) { + int innerA = a; + int innerB = b; + boolean go = false; + while (innerA < innerB) { + int innerCompare = arr[innerA].compareTo(arr[innerB]); + if (innerCompare > 0) { + write(bw, arr[b]); + b--; + go = true; + break; + } else if (innerCompare < 0) { + write(bw, arr[a]); + a++; + go = true; + break; + } + innerA++; + innerB--; + } + if (!go) { + write(bw, arr[a]); + a++; + } + } else { + write(bw, arr[a]); + a++; + } + } + + bw.flush(); + bw.close(); + } + + private static void write(BufferedWriter bw, String target) throws IOException { + if (count % 80 == 0) { + if (count!=0) { + bw.write("\n"); + } + } + bw.write(target); + count++; + } +} +```