Skip to content

Commit 45a5713

Browse files
committed
[level 0] Title: 암호 해독, Time: 2.49 ms, Memory: 76.2 MB -BaekjoonHub
1 parent a23c85c commit 45a5713

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# [level 0] 암호 해독 - 120892
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/120892)
4+
5+
### 성능 요약
6+
7+
메모리: 76.2 MB, 시간: 2.49 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 코딩테스트 입문
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 05월 08일 10:25:21
20+
21+
### 문제 설명
22+
23+
<p>군 전략가 머쓱이는 전쟁 중 적군이 다음과 같은 암호 체계를 사용한다는 것을 알아냈습니다.</p>
24+
25+
<ul>
26+
<li>암호화된 문자열 <code>cipher</code>를 주고받습니다.</li>
27+
<li>그 문자열에서 <code>code</code>의 배수 번째 글자만 진짜 암호입니다.</li>
28+
</ul>
29+
30+
<p>문자열 <code>cipher</code>와 정수 <code>code</code>가 매개변수로 주어질 때 해독된 암호 문자열을 return하도록 solution 함수를 완성해주세요.</p>
31+
32+
<hr>
33+
34+
<h5>제한사항</h5>
35+
36+
<ul>
37+
<li>1 ≤ <code>cipher</code>의 길이 ≤ 1,000</li>
38+
<li>1 ≤ <code>code</code> ≤ <code>cipher</code>의 길이</li>
39+
<li><code>cipher</code>는 소문자와 공백으로만 구성되어 있습니다.</li>
40+
<li>공백도 하나의 문자로 취급합니다.</li>
41+
</ul>
42+
43+
<hr>
44+
45+
<h5>입출력 예</h5>
46+
<table class="table">
47+
<thead><tr>
48+
<th>cipher</th>
49+
<th>code</th>
50+
<th>result</th>
51+
</tr>
52+
</thead>
53+
<tbody><tr>
54+
<td>"dfjardstddetckdaccccdegk"</td>
55+
<td>4</td>
56+
<td>"attack"</td>
57+
</tr>
58+
<tr>
59+
<td>"pfqallllabwaoclk"</td>
60+
<td>2</td>
61+
<td>"fallback"</td>
62+
</tr>
63+
</tbody>
64+
</table>
65+
<hr>
66+
67+
<h5>입출력 예 설명</h5>
68+
69+
<p>입출력 예 #1</p>
70+
71+
<ul>
72+
<li>"dfjardstddetckdaccccdegk" 의 4번째, 8번째, 12번째, 16번째, 20번째, 24번째 글자를 합친 "attack"을 return합니다.</li>
73+
</ul>
74+
75+
<p>입출력 예 #2</p>
76+
77+
<ul>
78+
<li>"pfqallllabwaoclk" 의 2번째, 4번째, 6번째, 8번째, 10번째, 12번째, 14번째, 16번째 글자를 합친 "fallback"을 return합니다.</li>
79+
</ul>
80+
81+
82+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public String solution(String cipher, int code) {
3+
String answer = "";
4+
5+
for(int i=0; i<cipher.length(); i++){
6+
if( (i+1) % code == 0) answer += Character.toString(cipher.charAt(i));
7+
}
8+
9+
return answer;
10+
}
11+
}

0 commit comments

Comments
 (0)