pkuImoogis / study-codingTest

0 stars 0 forks source link

1339 #353

Open geonnho0 opened 8 months ago

geonnho0 commented 8 months ago

문제 링크

geonnho0 commented 8 months ago

10의 자릿수가 큰 알파벳을 우선적으로 높은 값을 부여하면 돼요.

코드

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        String[] words = new String[N];
        int[] count = new int[26];
        for (int i = 0; i < N; i++) {
            words[i] = br.readLine();
            int len = words[i].length() - 1;
            for (int j = 0; j < words[i].length(); j++) {
                char c = words[i].charAt(j);
                count[c - 'A'] += (int) Math.pow(10, len);
                len--;
            }
        }

        Arrays.sort(count);
        int ans = 0, num = 9;
        for (int i = count.length - 1; i >= 0; i--)
            ans += (count[i] * num--);

        System.out.print(ans);
    }

}