Skip to content

Commit 3415411

Browse files
committed
2 parents 51565a9 + 70d5b14 commit 3415411

11 files changed

+315
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

Hongjoo/lv0/숫자제거배열.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
#1. input
3+
n,k = input().split()
4+
a = list(input().split())
5+
6+
# n,k = "5 2".split()
7+
# a = list("10 20 22 12 11".split())
8+
count = 0
9+
for i in range(len(a)):
10+
if k in a[i]:
11+
count+=1
12+
13+
answer = int(n) - count
14+
print(f"{answer}")
15+
16+
17+
# print ("Hello Goorm! Your input is " + user_input)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
n = int(input())
3+
sum = 0
4+
for i in range(n): #0,1,2,3
5+
sum+= (n-i)**2
6+
7+
print(sum)
8+
9+
10+
"""
11+
1,2,3,4
12+
1,2,3,4
13+
1,2,3,4
14+
1,2,3,4
15+
16(4*4)+(4-1)^2+ (4-2)^2 + (4-3)^1
16+
"""
17+

Hongjoo/lv1/구름스퀘어.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
# input
3+
events =[] # [start , end]
4+
# n = map(int, input())
5+
# for i in range(n):
6+
# s, e = map(int,input().split())
7+
# events.append([s,e])
8+
9+
n = int(input())
10+
for i in range(n):
11+
s,e = map(int, input().split())
12+
s= int(s); e= int(e)
13+
events.append([s,e])
14+
#우선순위 greedy : 끝나는 시간 빠른 순 정렬 -> 시작시간 빠른 순
15+
events.sort(key= lambda x: x[1])
16+
schdule = []
17+
end_time = -1
18+
count= 0
19+
for event in events :
20+
if event[0] > end_time :
21+
schdule.append(event)
22+
count+= 1
23+
end_time = event[1]
24+
25+
# count = len(schdule)
26+
27+
# print(f'schedule {schdule}, -> {count}')
28+
print(count)

Hongjoo/lv1/이진수정렬.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# n ,k = int(input().split()) # 개수, 특정 정수 위치
2+
# array = list(map(int,input().split()))
3+
def binary(num):
4+
tmp = ""
5+
while num !=0 :
6+
if num % 2 == 0 :
7+
tmp= "0"+tmp
8+
num = num // 2
9+
else :
10+
tmp = "1" + tmp
11+
num = num // 2
12+
return tmp
13+
14+
15+
n ,k = map(int,input().split()) # 개수, 특정 정수 위치
16+
array = list(map(int,input().split()))
17+
18+
bcount_o = []
19+
for o in array :
20+
l=binary(o).count("1")
21+
bcount_o.append([l,o])
22+
23+
# 내림차순 정렬
24+
bcount_o.sort(reverse= True)
25+
print(bcount_o[k-1][1])
26+

Hongjoo/lv2/괄호변환.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
answer = ''
2+
def u_notcorrect(u,v):
3+
#4-4 자르고 -> 뒤집기
4+
u = list(u[1:-1]) # 4-4
5+
if bool(u) :
6+
for i in range(len(u)):
7+
if u[i]==")":
8+
u[i] = "("
9+
else :
10+
u[i] = ")"
11+
12+
u = "".join(u)
13+
# 4-1, 4-2,4-3
14+
tmp= '(' + cut_wuv(v) +')' + str(u)
15+
return tmp
16+
17+
18+
def isCorrectString(u) : # u = p[s:e+1]
19+
count = 0
20+
for s in u :
21+
if s == "(" :
22+
count+=1
23+
elif s == ")" :
24+
count-=1
25+
if count < 0 :
26+
return False
27+
return count == 0
28+
29+
def cut_wuv(w):
30+
global answer
31+
# 1. 빈 문자열 -> 빈 문자열
32+
if w == "":
33+
return ""
34+
#2 w = u+v로 나누기
35+
e =0 #end idx 가리키는 two point
36+
while e < len(w):
37+
e +=1
38+
# u 구하기 #2
39+
if w[:e+1].count('(') == w[:e+1].count(')'):
40+
w=w[:] ;u = w[:e+1] ; v = w[e+1:]
41+
break
42+
43+
# 3.
44+
if not isCorrectString(u): #4올바른 괄호 문자열 x(onlt 균형 잡힌 문자열)
45+
answer+=str(u_notcorrect(u,v))
46+
return answer
47+
48+
else : #3 u 가 올바른 괄호 문자열
49+
answer = str(u) +cut_wuv(v)
50+
return answer
51+
52+
53+
def solution(p):
54+
global answer
55+
answer=cut_wuv(p)
56+
return answer

Hongjoo/lv2/큰수식찾기.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
def func(f):
3+
# 1, ops (종류) , 위치 찾기
4+
f = list(f)
5+
answer =0
6+
ops = []
7+
nums =[]
8+
s = 0
9+
for i in range(len(f)):
10+
if f[i] in ["+","*","-"] :
11+
ops.append([i,f[i]]) # [idx, + ]
12+
if len(f[s:i]) >= 1 :
13+
num= "".join(f[s:i])
14+
nums.append(num)
15+
s=i+1
16+
nums.append("".join(f[ops[-1][0]+1:]))
17+
nums= list(map(int, nums))
18+
# 연산자 우선순위
19+
20+
answer = nums[0]
21+
for j in range(len(ops)):
22+
if ops[j][1] == "*":
23+
answer *= nums[j+1]
24+
elif ops[j][1] == "-":
25+
answer -= nums[j+1]
26+
elif ops[j][1] == "+":
27+
answer += nums[j+1]
28+
return answer
29+
30+
31+
a,b = input().split()
32+
out=max(func(a),func(b))
33+
# print ("Hello Goorm! Your input is " + user_input)
34+
print(out)
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+
input = sys.stdin.readline
5+
6+
# BFS 함수
7+
def bfs(v, graph, visited):
8+
order = 1
9+
# 큐
10+
queue = deque([v])
11+
12+
while queue: # 큐가 빌 때까지 반복
13+
# 큐에서 원소를 하나 뽑아 출력한다.
14+
node = queue.popleft()
15+
if visited[node] == 0:
16+
visited[node] = order # 방문하면 순서 넣기
17+
order += 1 # 다음 순서로 넘어가기
18+
19+
for u in sorted(graph[node]): # 오름차순 인접노드 방문하기 위해 정렬
20+
if visited[u] == 0: # 방문 안 한 노드면 bfs 탐색
21+
queue.append(u)
22+
23+
# 초기화
24+
n, m, r = map(int, input().strip().split()) # n: 정점의 수, m: 간선의 수, r: 시작 정점
25+
graph = [[] for _ in range(n+1)]
26+
visited = [0] * (n+1)
27+
order = 1
28+
29+
# 그래프 연결
30+
for _ in range(m):
31+
u, v = map(int, input().strip().split())
32+
graph[u].append(v)
33+
graph[v].append(u)
34+
35+
bfs(r, graph, visited)
36+
37+
# 해당노드를 몇 번째로 방문했는지 출력
38+
for i in range(1, len(visited)):
39+
print(visited[i])
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import sys
2+
from collections import deque
3+
4+
input = sys.stdin.readline
5+
6+
# BFS 함수
7+
def bfs(v, graph, visited):
8+
queue = deque([v])
9+
order = 1
10+
while queue: # 큐가 빌 때까지 반복
11+
# 큐에서 원소를 하나 뽑아 node에 대입한다.
12+
node = queue.popleft()
13+
if visited[node] == 0:
14+
visited[node] = order # 방문하면 순서 넣기
15+
order += 1
16+
graph[node].sort(reverse=True) # 내림차순으로 인접노드 방문하기 위해 정렬
17+
for u in graph[node]:
18+
if visited[u] == 0: # 인접 노드 중에서 방문 안 한 노드면 bfs 탐색
19+
queue.append(u)
20+
21+
# 초기화
22+
n, m, r = map(int, input().strip().split()) # n: 정점의 수, m: 간선의 수, r: 시작 정점
23+
graph = [[] for _ in range(n+1)]
24+
visited = [0] * (n+1)
25+
order = 1
26+
27+
# 그래프 연결
28+
for _ in range(m):
29+
u, v = map(int, input().strip().split())
30+
graph[u].append(v)
31+
graph[v].append(u)
32+
33+
bfs(r, graph, visited)
34+
35+
# 해당노드를 몇 번째로 방문했는지 출력
36+
for i in range(1, len(visited)):
37+
print(visited[i])
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sys
2+
sys.setrecursionlimit(10**6) # 최대 재귀한도 깊이
3+
input = sys.stdin.readline
4+
5+
def dfs(v):
6+
global order
7+
visited[v] = order # 방문하면 순서 넣기
8+
order += 1 # 다음 순서로 넘어가기
9+
for u in sorted(graph[v]): # 오름차순으로 인접노드 방문하기 위해 정렬
10+
if visited[u] == 0: # 방문 안 한 노드면 dfs탐색
11+
dfs(u)
12+
13+
# n: 정점의 수, m: 간선의 수, r: 시작 정점
14+
n, m, r = map(int, input().strip().split())
15+
graph = [[] for _ in range(n + 1)]
16+
visited = [0] * (n + 1) # 방문 순서 저장. 0이면 방문 X
17+
order = 1
18+
19+
# m개의 간선 정보를 입력받아 그래프로 연결하기
20+
for _ in range(m):
21+
u, v = map(int, input().strip().split())
22+
graph[u].append(v)
23+
graph[v].append(u)
24+
25+
dfs(r)
26+
27+
# 해당노드를 몇 번째로 방문했는지 출력
28+
for i in range(1, n + 1):
29+
print(visited[i])

0 commit comments

Comments
 (0)