Skip to content

Commit d370e64

Browse files
authored
Merge pull request #723 from AlgorithmWithGod/JHLEE325
[20250823] BOJ / G4 / 단어 수학 / 이준희
2 parents ed5057a + 5ef0366 commit d370e64

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws Exception {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int N = Integer.parseInt(br.readLine());
9+
10+
int[] weight = new int[26];
11+
12+
for (int i = 0; i < N; i++) {
13+
String word = br.readLine();
14+
int len = word.length();
15+
for (int j = 0; j < len; j++) {
16+
char c = word.charAt(j);
17+
weight[c - 'A'] += Math.pow(10, len - j - 1);
18+
}
19+
}
20+
21+
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
22+
for (int w : weight) {
23+
if (w > 0) pq.add(w);
24+
}
25+
26+
int num = 9;
27+
int sum = 0;
28+
while (!pq.isEmpty()) {
29+
int val = pq.poll();
30+
sum += val * num--;
31+
}
32+
33+
System.out.println(sum);
34+
}
35+
}
36+
37+
```

0 commit comments

Comments
 (0)