Skip to content

Commit 70d5b14

Browse files
authored
Merge pull request #39 from zaqquum/main
김홍주 / 7월 1주차 / 6개
2 parents 2a9248a + a668b3e commit 70d5b14

File tree

6 files changed

+178
-0
lines changed

6 files changed

+178
-0
lines changed

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)

0 commit comments

Comments
 (0)