Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Commit 2c49a15

Browse files
committed
20220109
1 parent d3319a5 commit 2c49a15

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

opijae/programmers/괄호변환.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# u,v 분리 이때 u는 균형잡힌 괄호
2+
def split(p):
3+
cnt = 0
4+
for i in range(len(p)):
5+
if p[i] == '(':
6+
cnt += 1
7+
else:
8+
cnt -= 1
9+
# ( 와 ) 의 수가 같으면 return
10+
if cnt == 0:
11+
return p[: i + 1], p[i + 1 :]
12+
13+
# u가 올바른 괄호인지 확인
14+
def isRight(u):
15+
stack = []
16+
# 시작이 )면 false
17+
if u[0] ==')':
18+
return False
19+
# stack으로 올바른 괄호가 맞는지 확인
20+
for c in u:
21+
if stack and stack[-1] != c:
22+
stack.pop()
23+
else:
24+
stack.append(c)
25+
# stack이 비어있으면 True
26+
if stack:
27+
return False
28+
else:
29+
return True
30+
31+
# 문자열 뒤집음
32+
def convt(u):
33+
temp = ''
34+
for c in u:
35+
if c =='(':
36+
temp += ')'
37+
else:
38+
temp += '('
39+
return temp
40+
41+
# 문제 설명대로 구현
42+
def dfs(p):
43+
if len(p) == 0:
44+
return ''
45+
u,v = split(p)
46+
if isRight(u):
47+
return u + dfs(v)
48+
else:
49+
return '(' + dfs(v) + ')' + convt(u[1:-1])
50+
51+
52+
def solution(p):
53+
return dfs(p)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from collections import deque
2+
def solution(str1, str2):
3+
answer = 0
4+
# 대문자로 변경
5+
str1=str1.upper()
6+
str2=str2.upper()
7+
str1_list=deque()
8+
str2_list=deque()
9+
# 두글자씩 끊으면서 알파벳 아닌건 거름
10+
for i in range(0,len(str1)-1):
11+
temp=str1[i:i+2]
12+
if temp.isalpha():
13+
str1_list.append(temp)
14+
for i in range(0,len(str2)-1):
15+
temp=str2[i:i+2]
16+
if temp.isalpha():
17+
str2_list.append(temp)
18+
same=0
19+
total=len(str1_list)+len(str2_list)
20+
for i in range(len(str1_list)):
21+
a=str1_list.popleft()
22+
# 같은게 있는지 확인
23+
if a in str2_list:
24+
str2_list.remove(a)
25+
same+=1
26+
else:
27+
str1_list.append(a)
28+
sum_len=total-same
29+
try:
30+
answer=same/sum_len*65536
31+
except:
32+
answer=65536
33+
return int(answer)

opijae/programmers/메뉴리뉴얼.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from itertools import combinations
2+
from collections import Counter
3+
def solution(orders, course):
4+
answer = []
5+
# 메뉴를 오름차순으로 정렬
6+
s_orders=[sorted(order) for order in orders]
7+
for c in course:
8+
temp_list = []
9+
# 코스메뉴 수 많큼 코스 조합짜기
10+
for order in s_orders:
11+
temp = combinations(order,c)
12+
temp_list.extend(list(temp)) # 나올 수 있는 조합
13+
max_b=0
14+
# 많이 나온 순대로 코스요리 채택
15+
for a,b in Counter(temp_list).most_common():
16+
if b<2:
17+
break
18+
if max_b<=b:
19+
max_b = b
20+
answer.append(''.join(a))
21+
return sorted(answer)

0 commit comments

Comments
 (0)