Skip to content

Commit fc19b01

Browse files
authored
Merge pull request #60 from zaqquum/main
Hongjoo/9월 2-3주차/2문제
2 parents b21382a + f32ad40 commit fc19b01

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

Hongjoo/lv0/평행.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
(1)평행선 -> 같은 기울기
3+
(2) 두 직선이 일치하는 경우도
4+
"""
5+
6+
def solution(dots):
7+
# 모든 직선의 기울기 구하기
8+
# 1. 점 2개 선택
9+
# 2. 기울기
10+
answer = 0
11+
loops= []
12+
13+
for i in range(len(dots)) :
14+
for j in range(i+1, len(dots)) :
15+
x1 , y1 = dots[i]
16+
x2 , y2 = dots[j]
17+
print(f"### {x1} ,{y1} , {x2} , {y2}")
18+
output= (y1-y2)/(x1-x2+0.0001)
19+
loop = abs(output)
20+
print(f"##{loop}")
21+
for l in loops :
22+
if loop == l :
23+
return 1
24+
loops.append(loop)
25+
print("$" ,loops)
26+
27+
return answer

Hongjoo/lv2/압축.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'''
2+
LZW
3+
1. Dic = {seq_length = 1 단어들 }
4+
5+
2. in Dic 현재 입력 matching 된 단어중 가장 max length 가진 문자열 찾기 => w
6+
3.print(W의 index), input 에서 제거 pop
7+
4 입력에서 처리 되지 않은 다음 글자 c 있으면 -> w+c를 사전에 등재
8+
5.2로 regress
9+
| condition
10+
1. 대문자만
11+
2,dic_index : 1 ~
12+
13+
'''
14+
dic = [0 , "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"]
15+
def compression_check(left_w , dic):
16+
# 1 . dic에 w 의 여부
17+
# 2. W 와 total_c 찾기 : 2point matching 된 단어중 가장 max length -
18+
# answer =[] ;
19+
count = 0
20+
i = 0; j = len(left_w) # i : start ,j : end
21+
while i != j and j >= 0: # c가 없음 -> 끝
22+
# print("1" ,left_w[i:j] ,i , j)
23+
count+=1
24+
if left_w[i:j]in dic :
25+
print("2" , i, j)
26+
w = left_w[i:j]
27+
c = left_w[j]
28+
dic.append(w+c)
29+
print(w ,c,dic)
30+
idx = dic.index(w)
31+
# answer.append(idx)
32+
print("w_idx" , idx)
33+
# left_w = "" + c # 초기화
34+
i = j #업데이트
35+
return idx , j
36+
# print("#" , w , c , dic , left_w)
37+
38+
# print("-1")
39+
j=j-1
40+
# print(j)
41+
42+
43+
def solution(msg):
44+
answer = []
45+
46+
47+
# 1. inintialize dic
48+
# dic = [0 , "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"] # total 26 + "0" = 1 -> 1~ 26 only valid
49+
#2.
50+
a = 0 ; c ="a"
51+
answer = []
52+
a , j_c = compression_check(msg , dic)
53+
answer.append(a)
54+
55+
while j_c > 0 :
56+
a,j_c = compression_check(msg[j_c:] , dic)
57+
print(a)
58+
59+
# print("####", answer)
60+
return answer

0 commit comments

Comments
 (0)