File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments