문제는 이러하다.

 

 

기존의 알파벳과 다르게 a,b,k,d,e,g,h,i,l,m,n,ng,o,p,r,s,t,u,w,y 순으로만 사용되고,

여기서 눈 여겨 볼 점은

 

1. n과 o 사이의 ng

2. k의 위치

3. ng를 기준으로 앞 c, f, j 뒤 q, v, x, z 부재

 

정도인 것 같다.

풀이의 흐름은 다음과 같다.

 

1. c는 존재하지 않으며 그 위치에 k가 있으므로 입력을 받을 시 c -> k로 치환.

 

2. ng를 처리하기위해 ng 다음 알파벳인 o, p, r, ... , y를 char기준으로 +1씩 늘려줌.

예를 들면 ..., m, n, o(==ng), p(==o), q(==o), s(==r), t(==s), u(==t), ...

 

package baekjoon;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class 민식어_1599 {
    static class Word {
        String before, after;
        Word(String before) {
            this.before = before;
        }
    }
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(bf.readLine());
        ArrayList<Word> arr = new ArrayList<>();

        for(int i=0;i<N;i++) {
            String input = bf.readLine();
            Word word = new Word(input);
            word.after = "";

            for(int j=0;j<input.length();j++) {
                if(input.charAt(j)=='g' && j != 0 && input.charAt(j-1)=='n') continue;
                if(input.charAt(j) == 'k') {
                    word.after += "c"; continue;
                } else if(input.charAt(j) >= 'n') {
                    if(input.charAt(j)=='n' && j < input.length()-1 && input.charAt(j+1)=='g') {
                        word.after += "o"; continue;
                    } else if(input.charAt(j)=='n') {
                        word.after += "n"; continue;
                    } else {
                        word.after += Character.toString((char)(input.charAt(j) + 1));
                    }
                } else {
                    word.after += Character.toString(input.charAt(j));
                }
            }
            arr.add(word);
        }

        Collections.sort(arr, new Comparator<Word>() {

            @Override
            public int compare(Word o1, Word o2) {
                return o1.after.compareTo(o2.after);
            }
            
        });
        for(Word w : arr) {
            System.out.println(w.before);
        }
    }
}

 

원래는 그냥 char배열로 받고 출력 전 원래의 단어로 돌릴까 싶었지만, 아무래도 새로운 class로 변경 전 알파벳과 변경 후 알파벳을 각각 저장하는 게 날 것 같았다.

 

아무튼, 성공!

+ Recent posts