Skip to content

Commit 0a29fd1

Browse files
committed
[level 1] Title: 둘만의 암호, Time: 13.41 ms, Memory: 89.8 MB -BaekjoonHub
1 parent 0bd512d commit 0a29fd1

2 files changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# [level 1] 둘만의 암호 - 155652
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/155652)
4+
5+
### 성능 요약
6+
7+
메모리: 89.8 MB, 시간: 13.41 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 연습문제
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2025년 05월 27일 17:18:04
20+
21+
### 문제 설명
22+
23+
<p>두 문자열 <code>s</code>와 <code>skip</code>, 그리고 자연수 <code>index</code>가 주어질 때, 다음 규칙에 따라 문자열을 만들려 합니다. 암호의 규칙은 다음과 같습니다.</p>
24+
25+
<ul>
26+
<li>문자열 <code>s</code>의 각 알파벳을 <code>index</code>만큼 뒤의 알파벳으로 바꿔줍니다.</li>
27+
<li><code>index</code>만큼의 뒤의 알파벳이 <code>z</code>를 넘어갈 경우 다시 <code>a</code>로 돌아갑니다.</li>
28+
<li><code>skip</code>에 있는 알파벳은 제외하고 건너뜁니다.</li>
29+
</ul>
30+
31+
<p>예를 들어 <code>s</code> = "aukks", <code>skip</code> = "wbqd", <code>index</code> = 5일 때, a에서 5만큼 뒤에 있는 알파벳은 f지만 [b, c, d, e, f]에서 'b'와 'd'는 <code>skip</code>에 포함되므로 세지 않습니다. 따라서 'b', 'd'를 제외하고 'a'에서 5만큼 뒤에 있는 알파벳은 [c, e, f, g, h] 순서에 의해 'h'가 됩니다. 나머지 "ukks" 또한 위 규칙대로 바꾸면 "appy"가 되며 결과는 "happy"가 됩니다.</p>
32+
33+
<p>두 문자열 <code>s</code>와 <code>skip</code>, 그리고 자연수 <code>index</code>가 매개변수로 주어질 때 위 규칙대로 <code>s</code>를 변환한 결과를 return하도록 solution 함수를 완성해주세요.</p>
34+
35+
<hr>
36+
37+
<h5>제한사항</h5>
38+
39+
<ul>
40+
<li>5 ≤ <code>s</code>의 길이 ≤ 50</li>
41+
<li>1 ≤ <code>skip</code>의 길이 ≤ 10</li>
42+
<li><code>s</code>와 <code>skip</code>은 알파벳 소문자로만 이루어져 있습니다.
43+
44+
<ul>
45+
<li><code>skip</code>에 포함되는 알파벳은 <code>s</code>에 포함되지 않습니다.</li>
46+
</ul></li>
47+
<li>1 ≤ <code>index</code> ≤ 20</li>
48+
</ul>
49+
50+
<hr>
51+
52+
<h5>입출력 예</h5>
53+
<table class="table">
54+
<thead><tr>
55+
<th>s</th>
56+
<th>skip</th>
57+
<th>index</th>
58+
<th>result</th>
59+
</tr>
60+
</thead>
61+
<tbody><tr>
62+
<td>"aukks"</td>
63+
<td>"wbqd"</td>
64+
<td>5</td>
65+
<td>"happy"</td>
66+
</tr>
67+
</tbody>
68+
</table>
69+
<hr>
70+
71+
<h5>입출력 예 설명</h5>
72+
73+
<p>입출력 예 #1<br>
74+
본문 내용과 일치합니다.</p>
75+
76+
77+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public String solution(String s, String skip, int index) {
3+
String answer = "";
4+
5+
for(char c : s.toCharArray()){
6+
int cnt = 0;
7+
8+
while(cnt < index){
9+
if(c == 'z'){
10+
c = 'a';
11+
}else{
12+
c++;
13+
}
14+
15+
if(!skip.contains(String.valueOf(c))){
16+
cnt++;
17+
}
18+
19+
}
20+
answer+=c;
21+
}
22+
23+
return answer;
24+
}
25+
}

0 commit comments

Comments
 (0)