포스트

암호 해독

https://school.programmers.co.kr/learn/courses/30/lessons/120892

문제

  • 문제 풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public class Solution {
    public String solution(String cipher, int code) {
        StringBuilder result = new StringBuilder();
        for (int i = code - 1; i < cipher.length(); i += code) {
            result.append(cipher.charAt(i));
        }
        return result.toString();
    }

    public static void main(String[] args) {
        Solution sol = new Solution();
        System.out.println(sol.solution("dfjardstddetckdaccccdegk", 4)); // 출력: "attack"
        System.out.println(sol.solution("pfqallllabwaoclk", 2));         // 출력: "fallback"
    }
}

이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.