Dev.baelanche

[백준 14584] 암호 해독 본문

Data Structure & Algorithm/PS - JAVA

[백준 14584] 암호 해독

baelanche 2019. 7. 17. 21:26
반응형

 

 

매 케이스마다 주어진 문자열을 한칸씩 밀어주면서 사전의 단어를 포함하는지 확인하면 된다.

 

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String cipher = sc.next();
        
        int n = sc.nextInt();
        String s[] = new String[n];
        for(int i=0; i<n; i++)
            s[i] = sc.next();
        
        for(int i=0; i<26; i++) {
            String temp = "";
            for(int j=0; j<cipher.length(); j++)
                temp += (char)((cipher.charAt(j) - 'a' + i) % 26 + 'a');
            
            for(int j=0; j<n; j++) {
                if(temp.contains(s[j])) {
                    System.out.println(temp);
                    return;
                }
            }
        }
    }
}
반응형
Comments