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