[ 프로그래머스 ] #84512 : 모음사전 - JAVA

🔗 모음사전

import java.util.*;
class Solution {
    public int solution(String word) {
        // A : 0
        // E : 1
        // I : 2
        // O : 3
        // U : 4

        int []weight=new int [5];

        // 가중치 계산 
        for(int i=0;i<5;i++){
            for(int j=0;j<5-i;j++){
                weight[i]+=Math.pow(5,j);
            }
        }

        String []alpha={"A","E","I","O","U"};
        Map<String,Integer> map=new HashMap<>();
        for(int i=0;i<alpha.length;i++){
            map.put(alpha[i],i);
        }

        int answer=0;

        // 자리 수 순회
        for(int i=0;i<word.length();i++){
            String str=String.valueOf(word.charAt(i));
            answer+=map.get(str)*weight[i]+1;
        }

        return answer;
    }
}