Skip to content

Commit 6ee0658

Browse files
authored
Merge pull request #1190 from AlgorithmWithGod/Seol-JY
[20251021] BOJ / G4 / 단어 수학 / 설진영
2 parents 033ab0d + cdbf985 commit 6ee0658

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws IOException {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
int n = Integer.parseInt(br.readLine());
9+
10+
Map<Character, Integer> weights = new HashMap<>();
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+
int weight = (int) Math.pow(10, len - 1 - j);
18+
weights.put(c, weights.getOrDefault(c, 0) + weight);
19+
}
20+
}
21+
22+
List<Integer> weightList = new ArrayList<>(weights.values());
23+
weightList.sort((a, b) -> b - a);
24+
25+
int result = 0;
26+
int digit = 9;
27+
for (int weight : weightList) {
28+
result += weight * digit;
29+
digit--;
30+
}
31+
32+
System.out.println(result);
33+
}
34+
}
35+
```

0 commit comments

Comments
 (0)