File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ package Week2 .공통 .둘만의암호 ;
2
+
3
+ public class jiyoon {
4
+ class Solution {
5
+ public String solution (String s , String skip , int index ) {
6
+ // answer만들 때 사용할 alphabet문자열(skip에 포함된 문자 제외)
7
+ String alphabet = "abcdefghijklmnopqrstuvwxyz" ;
8
+
9
+ for (int i = 0 ; i < skip .length (); i ++) {
10
+ char c = skip .charAt (i );
11
+
12
+ // skip에 포함된 문자 제거
13
+ alphabet = alphabet .replace (String .valueOf (c ), "" );
14
+ }
15
+
16
+ String answer = "" ;
17
+
18
+ for (int i = 0 ; i < s .length (); i ++) {
19
+ char c = s .charAt (i );
20
+
21
+ // alphabet에서 s에 포함된 문자의 위치 찾기
22
+ int position = alphabet .indexOf (String .valueOf (c ));
23
+
24
+ // 이동시킬 위치
25
+ int total = position + index ;
26
+
27
+ // 이동시킬 위치가 alphabet을 넘어간다면('z'를 넘어간다면, 'a'부터 시작)
28
+ while (total >= alphabet .length ()) {
29
+ total -= alphabet .length ();
30
+ }
31
+ answer += alphabet .charAt (total );
32
+
33
+ }
34
+
35
+ return answer ;
36
+ }
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments