Skip to content

Commit 732b587

Browse files
authored
[20250811] BOJ / G3 / 합 / 이종환
1 parent e155e45 commit 732b587

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

0224LJH/202508/11 BOJ 합.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
```java
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.*;
7+
8+
9+
public class Main {
10+
11+
static String[] words;
12+
static long[] alphabetCnt;
13+
static long ans;
14+
static int numCnt;
15+
static HashSet<Integer> firstLetter = new HashSet<>();
16+
17+
public static void main(String[] args) throws IOException {
18+
init();
19+
process();
20+
print();
21+
}
22+
23+
private static void init() throws IOException {
24+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
25+
numCnt = Integer.parseInt(br.readLine());
26+
words = new String[numCnt];
27+
for (int i = 0; i < numCnt; i++) {
28+
words[i] = br.readLine();
29+
}
30+
31+
alphabetCnt = new long[10];
32+
ans = 0;
33+
}
34+
35+
private static void process() throws IOException {
36+
for (int i = 0; i < numCnt; i++){
37+
String t = words[i];
38+
firstLetter.add(t.charAt(0)-'A');
39+
for (int j = 0; j < t.length(); j++) {
40+
alphabetCnt[t.charAt(j)-'A'] += (long) Math.pow(10,t.length() -1 -j);
41+
}
42+
}
43+
44+
long minCnt = Long.MAX_VALUE;
45+
int minCntAlphabet = -1;
46+
for (int i = 0; i <= 9; i++){
47+
if (firstLetter.contains(i))continue;
48+
49+
if (alphabetCnt[i] < minCnt) {
50+
minCnt = alphabetCnt[i];
51+
minCntAlphabet = i;
52+
}
53+
}
54+
55+
alphabetCnt[minCntAlphabet] = 0;
56+
57+
Arrays.sort(alphabetCnt);
58+
59+
for (int i = 9; i >= 0; i--){
60+
ans += alphabetCnt[i] * i;
61+
}
62+
63+
64+
}
65+
66+
67+
private static void print() {
68+
System.out.println(ans);
69+
}
70+
}
71+
```

0 commit comments

Comments
 (0)