Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions JHLEE325/202508/23 BOJ G4 단어 수학.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
```java
import java.io.*;
import java.util.*;

public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());

int[] weight = new int[26];

for (int i = 0; i < N; i++) {
String word = br.readLine();
int len = word.length();
for (int j = 0; j < len; j++) {
char c = word.charAt(j);
weight[c - 'A'] += Math.pow(10, len - j - 1);
}
}

PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
for (int w : weight) {
if (w > 0) pq.add(w);
}

int num = 9;
int sum = 0;
while (!pq.isEmpty()) {
int val = pq.poll();
sum += val * num--;
}

System.out.println(sum);
}
}

```