import java.util.*;

class Solution {
    public String[] solution(String[] files) {
        String[] answer = new String[files.length];
        String[][] file = new String[files.length][3];
        
        for(int i=0; i<files.length; i++) {
            int index = 0;
            int state = 0;
            for(int j=0; j<files[i].length(); j++) {
                char c = files[i].charAt(j);
                
                if(state==0 && c>='0' && c<='9') {
                    file[i][0] = files[i].substring(0, j);
                    index = j;
                    state = 1;
                }
                
                if(state==1 && !(c>='0'&&c<='9')) {
                    file[i][1] = files[i].substring(index, j);
                    file[i][2] = files[i].substring(j, files[i].length());
                    state = 2;
                }
            }
            
            if(state == 1) {
                file[i][1] = files[i].substring(index, files[i].length());
                file[i][2] = "";
            }
        }
        
        Arrays.sort(file, new Comparator<String[]>(){
            @Override
            public int compare(String[] s1, String[] s2) {
                String ss1 = s1[0].toUpperCase();
                String ss2 = s2[0].toUpperCase();
                
                if(ss1.equals(ss2)) { return Integer.parseInt(s1[1])-Integer.parseInt(s2[1]); }
                
                return ss1.compareTo(ss2);
            }
        });
        
        for(int i=0; i<answer.length; i++) { answer[i] = file[i][0]+file[i][1]+file[i][2]; }
        
        return answer;
    }
}

'Problem Solving > Programmers' 카테고리의 다른 글

[Level 2] 올바른 괄호  (0) 2022.04.07
[Level 2] 가장 큰 정사각형 찾기  (0) 2022.04.07
[Level 2] 방문 길이  (0) 2022.04.07
[Level 2] 스킬트리  (0) 2022.04.07
[Level 2] n^2 배열 자르기  (0) 2022.04.07