From 732b587c92fdf7dfe3ee0129988dfb4e625af726 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Mon, 11 Aug 2025 23:14:34 +0900 Subject: [PATCH] =?UTF-8?q?[20250811]=20BOJ=20/=20G3=20/=20=ED=95=A9=20/?= =?UTF-8?q?=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 --- "0224LJH/202508/11 BOJ \355\225\251.md" | 71 ++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "0224LJH/202508/11 BOJ \355\225\251.md" diff --git "a/0224LJH/202508/11 BOJ \355\225\251.md" "b/0224LJH/202508/11 BOJ \355\225\251.md" new file mode 100644 index 00000000..70218982 --- /dev/null +++ "b/0224LJH/202508/11 BOJ \355\225\251.md" @@ -0,0 +1,71 @@ +```java + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + + +public class Main { + + static String[] words; + static long[] alphabetCnt; + static long ans; + static int numCnt; + static HashSet firstLetter = new HashSet<>(); + + 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)); + numCnt = Integer.parseInt(br.readLine()); + words = new String[numCnt]; + for (int i = 0; i < numCnt; i++) { + words[i] = br.readLine(); + } + + alphabetCnt = new long[10]; + ans = 0; + } + + private static void process() throws IOException { + for (int i = 0; i < numCnt; i++){ + String t = words[i]; + firstLetter.add(t.charAt(0)-'A'); + for (int j = 0; j < t.length(); j++) { + alphabetCnt[t.charAt(j)-'A'] += (long) Math.pow(10,t.length() -1 -j); + } + } + + long minCnt = Long.MAX_VALUE; + int minCntAlphabet = -1; + for (int i = 0; i <= 9; i++){ + if (firstLetter.contains(i))continue; + + if (alphabetCnt[i] < minCnt) { + minCnt = alphabetCnt[i]; + minCntAlphabet = i; + } + } + + alphabetCnt[minCntAlphabet] = 0; + + Arrays.sort(alphabetCnt); + + for (int i = 9; i >= 0; i--){ + ans += alphabetCnt[i] * i; + } + + + } + + + private static void print() { + System.out.println(ans); + } +} +``` \ No newline at end of file