Skip to content

Commit 135bda2

Browse files
authored
Merge pull request #62 from Suxxxxhyun/Suxxxxhyun
[Solved] PRG_둘만의 암호
2 parents dc01625 + e664498 commit 135bda2

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package Week2.공통.둘만의암호;
2+
3+
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
7+
// 자바는 1차원배열에서는 indexOf를 지원하지 않는다.
8+
// indexOf는 ArrayList에서 지원가능하다.
9+
// List<Character> alpha = Arrays.asList(리스트);
10+
public class suhyun {
11+
12+
static List<Character> alpha = Arrays.asList('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
13+
public static String solution(String s, String skip, int index) {
14+
String answer = "";
15+
for(int i=0; i<s.length(); i++){
16+
int count = 0;
17+
int start = alpha.indexOf(s.charAt(i));
18+
int idx = start;
19+
boolean cont = false;
20+
while(count < index){
21+
idx += 1;
22+
if(idx > 25){
23+
idx %= 26;
24+
}
25+
cont = false;
26+
for(int j=0; j<skip.length(); j++){
27+
if(skip.charAt(j) == alpha.get(idx)){
28+
cont = true;
29+
}
30+
}
31+
if (!cont) {
32+
count += 1;
33+
}
34+
// System.out.print(idx + " ");
35+
}
36+
// System.out.println();
37+
answer += alpha.get(idx);
38+
}
39+
return answer;
40+
}
41+
42+
public static void main(String[] args){
43+
String s = "aukks";
44+
String skip = "wbqd";
45+
int index = 5;
46+
System.out.println(solution(s, skip, index));
47+
}
48+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
2+
def solution(s, skip, index):
3+
answer = ''
4+
for c in s:
5+
count = 0
6+
c_idx = alpha.index(c)
7+
while count < index:
8+
c_idx += 1
9+
if c_idx > 25:
10+
c_idx %= 26
11+
if alpha[c_idx] not in skip:
12+
count += 1
13+
answer += alpha[c_idx]
14+
return answer
15+
16+
s = "aukks"
17+
skip = "wbqd"
18+
index = 5
19+
print(solution(s, skip, index))

Week2/공통/둘만의암호/test.java

-4
This file was deleted.

0 commit comments

Comments
 (0)