From 84d6bb1b1710b19bf8407c4950e05e1b1ed5b6f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=88=98=EB=AF=BC?= Date: Fri, 11 Oct 2024 17:08:56 +0900 Subject: [PATCH] CT_278 --- BOJ/Java/src/S3/Boj_25624_SNUPTI.java | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 BOJ/Java/src/S3/Boj_25624_SNUPTI.java diff --git a/BOJ/Java/src/S3/Boj_25624_SNUPTI.java b/BOJ/Java/src/S3/Boj_25624_SNUPTI.java new file mode 100644 index 00000000..0e087095 --- /dev/null +++ b/BOJ/Java/src/S3/Boj_25624_SNUPTI.java @@ -0,0 +1,67 @@ +package S3; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Scanner; + +public class Boj_25624_SNUPTI { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int[] alphabet = new int[26]; + Arrays.fill(alphabet, -1); + PriorityQueue[] order = new PriorityQueue[26]; + for (int i = 0; i < 26; i++) { + order[i] = new PriorityQueue<>(); + } + Map dict = new HashMap<>(); + String snupti; + boolean able = true; + + int sz = scanner.nextInt(); + int tc = scanner.nextInt(); + scanner.nextLine(); // consume the newline character + + for (int k = 0; k < tc; k++) { + snupti = scanner.nextLine(); + if (dict.containsKey(snupti)) { + able = false; + } else { + dict.put(snupti, true); + } + if (!able) { + continue; + } + for (int n = 0; n < sz; n++) { + if (alphabet[snupti.charAt(n) - 'A'] == -1) { + alphabet[snupti.charAt(n) - 'A'] = n; + order[n].offer(snupti.charAt(n)); + } else if (alphabet[snupti.charAt(n) - 'A'] != n) { + able = false; + } + } + } + + if (!able) { + System.out.println("NO"); + } else { + int sum = 1; + for (int n = 0; n < sz; n++) { + sum *= order[n].size(); + } + if (sum != tc) { + System.out.println("NO"); + } else { + System.out.println("YES"); + for (int n = 0; n < sz; n++) { + while (!order[n].isEmpty()) { + System.out.print(order[n].poll()); + } + System.out.println(); + } + } + } + scanner.close(); + } +}