Skip to content

Commit c496f8a

Browse files
committed
update
1 parent 7c848f4 commit c496f8a

File tree

3 files changed

+122
-2
lines changed

3 files changed

+122
-2
lines changed

week14/haenim/순위검색.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ def solution(info, query):
3232
elif j != 4 and data.find(q[j]) == -1:
3333
break
3434

35-
36-
3735

3836
answer.append(count)
3937

@@ -46,3 +44,20 @@ def solution(info, query):
4644
["java and backend and junior and pizza 100", "python and frontend and senior and chicken 200",
4745
"cpp and - and senior and pizza 250", "- and backend and senior and - 150", "- and - and - and chicken 100",
4846
"- and - and - and - 150"]))
47+
48+
49+
"""
50+
1. 주어진 info에 대해 '-'를 포함한 모든 만족하는 쿼리의 종류를 만든다.
51+
52+
java backend junior pizza 150
53+
54+
- backend junior pizza 150
55+
java - junior pizza 150
56+
57+
2. 딕셔너리 구성
58+
59+
3. 주어진 query에 대해 딕셔너리를 확인하고,값이 있을 경우 lower bound를 통해 쿼리보다 점수가 같거나 높은 갯수 찾기
60+
61+
62+
63+
"""
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
T = int(input());
2+
3+
4+
for i in range(T):
5+
N = int(input())
6+
node_info = [0]*(N+1)
7+
8+
for i in range(N-1):
9+
parent, child = map(int,input().split())
10+
# [0, 8, 10, 16, 8, 8, 4, 6, 0, 5, 4, 10, 16, 1, 1, 6, 10]
11+
# 1의 부모는 8, 2의 부모는 10 ...
12+
node_info[child] = parent
13+
14+
n1, n2 = map(int,input().split())
15+
n1_ancestors, n2_ancestors = [n1],[n2]
16+
17+
18+
# 겹치는 조상이 나올 때 까지 반복
19+
while list(set(n1_ancestors).intersection(n2_ancestors)) == []:
20+
p = node_info[n1]
21+
n1_ancestors.append(p) #[16, 10, 4]
22+
n1 = p
23+
24+
p = node_info[n2]
25+
n2_ancestors.append(p) # [7, 6, 4]
26+
n2 = p
27+
28+
29+
result = set(n1_ancestors).intersection(n2_ancestors) # {4}
30+
print("".join(map(str,result))) # 4
31+
32+
33+
34+
"""
35+
#시간초과
36+
37+
T = int(input());
38+
39+
40+
# 자식 : 부모 형식으로 딕셔너리 바꿈
41+
# {(14, 13): 1, (5, 4, 1): 8, (16, 11, 2): 10, (9,): 5, (6, 10): 4, (15, 7): 6, (3, 12): 16}
42+
def reverse(item):
43+
key, value = item
44+
return tuple(value),key
45+
46+
for i in range(T):
47+
N = int(input())
48+
node_info = dict()
49+
50+
# 부모 : 자식들 형식으로 딕셔너리 생성
51+
#{1: [14, 13], 8: [5, 4, 1], 10: [16, 11, 2], 5: [9], 4: [6, 10], 6: [15, 7], 16: [3, 12]}
52+
for i in range(N-1):
53+
parent, child = map(int,input().split())
54+
55+
if parent in node_info:
56+
node_info[parent].append(child)
57+
else:
58+
node_info[parent] = [child]
59+
60+
node_info = dict(map(reverse , node_info.items()))
61+
62+
n1, n2 = map(int,input().split())
63+
n1_ancestors, n2_ancestors = [n1],[n2]
64+
65+
66+
while list(set(n1_ancestors).intersection(n2_ancestors)) == []:
67+
for key,value in node_info.items():
68+
if n1 in key:
69+
n1_ancestors.append(value)
70+
n1 = value
71+
break;
72+
73+
if n2 in key:
74+
n2_ancestors.append(value)
75+
n2 = value
76+
break;
77+
78+
#print(node_info)
79+
#print(n1_ancestors)
80+
#print(n2_ancestors)
81+
result = set(n1_ancestors).intersection(n2_ancestors)
82+
print("".join(map(str,result)))
83+
"""
84+
85+
86+
87+
88+
89+
90+

week15/heanim/문자열집합.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
n,m = map(int, input().split())
2+
s = []
3+
check = []
4+
count = 0
5+
6+
for i in range(n):
7+
s.append(input())
8+
9+
for i in range(m):
10+
check = input()
11+
if check in s:
12+
count += 1
13+
14+
15+
print(count)

0 commit comments

Comments
 (0)