Skip to content

Commit 4b8a2f2

Browse files
authored
Merge pull request #80 from zaqquum/main
Hongjoo/ 11์›” 1์ฃผ์ฐจ / 2๋ฌธ์ œ
2 parents 2049fb0 + 0d95e78 commit 4b8a2f2

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def solution(s):
2+
answer = 0
3+
opps = 1
4+
5+
if s[0] == "+" :
6+
opps = 1
7+
answer = int(s[1:])
8+
elif s[0] == "-" :
9+
opps = 0
10+
answer = int(s[1:]) * (-1)
11+
else :
12+
answer = int(s)
13+
14+
15+
return answer
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def solution(num):
2+
answer = ''
3+
if num == 0 or num %2 ==0 : # even
4+
answer = "Even"
5+
elif num % 2 == 1 : # odd
6+
answer = "Odd"
7+
return answer
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
from collections import deque
3+
4+
def topology_sort() :
5+
result = []
6+
q = deque()
7+
8+
# 1. indegree= 0์ธ ๋…ธ๋“œ๋ฅผ ํ์— ์‚ฝ์ž…
9+
for i in range(1,n+1) :
10+
if indegree[i] == 0:
11+
q.append(i)
12+
13+
# 2. ํ๊ฐ€ ๋นŒ ๋•Œ ๊นŒ์ง„ ๋ฐ˜๋ณต
14+
while q :
15+
# 2-1 ํ์—์„œ ์›์†Œ ๊บผ๋‚ด๊ธฐ
16+
now = q.popleft()
17+
result.append(now) # resut == queue ๊บผ๋‚ด๋Š” ์ˆœ์„œ
18+
# 2-2 ํ•ด๋‹น ๋…ธ๋“œ์™€ ์—ฐ๊ฒฐ๋œ ๋…ธ๋“œ (outdegree)๋“ค์˜ ์ง„์ž… ์ฐจ์ˆ˜์—์„œ 1 ๋นผ๊ธฐ
19+
for j in graph[now] :
20+
indegree[j] -=1
21+
#2-3. ์ƒˆ๋กญ๊ฒŒ indegree=0 ์ธ ๋…ธ๋“œ๋ฅผ ํ์— ์‚ฝ์ž…
22+
if indegree[j] == 0 :
23+
q.append(j)
24+
25+
# 3.์œ„์ƒ์ •๋ ฌ์„ ์ˆ˜ํ–‰ํ•œ ๊ฒฐ๊ณผ ์ถœ๋ ฅ
26+
for i in result :
27+
print(i,end = " ")
28+
29+
n, m = map(int, sys.stdin.readline().split())
30+
#graph ๋งŒ๋“ค๊ธฐ
31+
indegree = [0] * (n+1) # indegree list
32+
graph = [[] for _ in range(n+1)]
33+
for i in range(m):
34+
a,b = map(int , sys.stdin.readline().split())# a์•ž -> b๋’ค
35+
graph[a].append(b)
36+
indegree[b] += 1
37+
38+
39+
topology_sort()

0 commit comments

Comments
ย (0)