first commit

from old repository to a new repository
This commit is contained in:
Gyubin Han
2024-04-30 16:59:10 +09:00
commit 2600340c03
93 changed files with 1610 additions and 0 deletions

12
boj/1003.py Normal file
View File

@@ -0,0 +1,12 @@
from sys import stdin
t=int(stdin.readline().rstrip())
for _ in range(t):
fibo=[0,1]
z=[1,0]
n=int(stdin.readline().rstrip())
for i in range(2,n+1):
fibo.append(fibo[i-1]+fibo[i-2])
z.append(z[i-1]+z[i-2])
print(z[n],fibo[n])

18
boj/1032.py Normal file
View File

@@ -0,0 +1,18 @@
from sys import stdin
n=int(stdin.readline().rstrip())
pattern=""
plen=0
for _ in range(n):
name=stdin.readline().rstrip()
if plen==0:
pattern=name
plen=len(pattern)
else:
for i in range(plen):
if pattern[i]=='?' or pattern[i]==name[i]:
continue
else:
pattern=pattern[:i]+'?'+pattern[i+1:]
print(pattern)

5
boj/10807.py Normal file
View File

@@ -0,0 +1,5 @@
n=int(input())
arr=list(map(int,input().split()))
s=int(input())
print(arr.count(s))

12
boj/10814.py Normal file
View File

@@ -0,0 +1,12 @@
from sys import stdin
n=int(stdin.readline().rstrip())
arr=[]
for _ in range(n):
age,name=map(str,stdin.readline().rstrip().split())
arr.append([int(age),name])
arr.sort(key=lambda x:x[0])
for r in arr:
print(r[0],r[1])

12
boj/10815.py Normal file
View File

@@ -0,0 +1,12 @@
from sys import stdin
n=int(stdin.readline().rstrip())
narr=set(map(int,stdin.readline().rstrip().split()))
m=int(stdin.readline().rstrip())
marr=list(map(int,stdin.readline().rstrip().split()))
for i in range(m):
if marr[i] in narr:
print(1,end=" ")
else:
print(0,end=" ")

22
boj/10816.py Normal file
View File

@@ -0,0 +1,22 @@
from sys import stdin
n=int(stdin.readline().rstrip())
narr=list(map(int,stdin.readline().rstrip().split()))
cnt=dict()
for i in narr:
if not i in cnt:
cnt[i]=1
else:
cnt[i]+=1
# print(cnt.keys())
# k=cnt.keys()
# for i in k:
# print(cnt[i])
m=int(stdin.readline().rstrip())
marr=list(map(int,stdin.readline().rstrip().split()))
for i in marr:
if i in cnt:
print(cnt[i],end=" ")
else:
print(0,end=" ")

7
boj/10818.py Normal file
View File

@@ -0,0 +1,7 @@
from sys import stdin
n=int(stdin.readline().rstrip())
arr=list(map(int,stdin.readline().rstrip().split()))
# 정렬을 한번 하고나서 맨 처음과 끝을 출력하여 최대, 최소값을 출력
arr.sort()
print(arr[0],arr[-1])

27
boj/10828.py Normal file
View File

@@ -0,0 +1,27 @@
from sys import stdin
n=int(stdin.readline().rstrip())
stack=[]
for _ in range(n):
s=stdin.readline().rstrip().split()
if len(s)==1:
if s[0]=='pop':
if len(stack)==0:
print(-1)
else:
print(stack.pop())
elif s[0]=='top':
if len(stack)==0:
print(-1)
else:
print(stack[-1])
elif s[0]=='size':
print(len(stack))
else:
if len(stack)==0:
print(1)
else:
print(0)
else:
stack.append(int(s[1]))

32
boj/10845.py Normal file
View File

@@ -0,0 +1,32 @@
from sys import stdin
n=int(stdin.readline().rstrip())
q=[]
for _ in range(n):
s=stdin.readline().rstrip().split()
if len(s)==1:
if s[0]=='pop':
if len(q)==0:
print(-1)
else:
print(q.pop(0))
elif s[0]=='front':
if len(q)==0:
print(-1)
else:
print(q[0])
elif s[0]=='back':
if len(q)==0:
print(-1)
else:
print(q[-1])
elif s[0]=='size':
print(len(q))
else:
if len(q)==0:
print(1)
else:
print(0)
else:
q.append(int(s[1]))

42
boj/10866.py Normal file
View File

@@ -0,0 +1,42 @@
from sys import stdin
from collections import deque
n=int(stdin.readline().rstrip())
dq=deque()
for _ in range(n):
s=stdin.readline().rstrip().split()
if len(s)==1:
if s[0]=='pop_front':
if len(dq)==0:
print(-1)
else:
print(dq.popleft())
elif s[0]=='pop_back':
if len(dq)==0:
print(-1)
else:
print(dq.pop())
elif s[0]=='front':
if len(dq)==0:
print(-1)
else:
print(dq[0])
elif s[0]=='back':
if len(dq)==0:
print(-1)
else:
print(dq[-1])
elif s[0]=='size':
print(len(dq))
else:
if len(dq)==0:
print(1)
else:
print(0)
else:
if s[0]=='push_front':
dq.appendleft(int(s[1]))
else:
dq.append(int(s[1]))

5
boj/10950.py Normal file
View File

@@ -0,0 +1,5 @@
n=int(input())
for _ in range(n):
a,b=map(int,input().split())
print(a+b)

10
boj/10951.py Normal file
View File

@@ -0,0 +1,10 @@
# 별도의 입력 갯수를 정하지 않고 계속 입력받기 위해 while문 사용
while True:
# EOF를 통해서 프로그램이 종료되는 구조임.
try:
a,b=map(int,input().split())
print(a+b)
# EOF가 발생한 경우, EOFError라는 예외가 발생하여, 이 예외를 처리
except EOFError:
# 상위에서 동작하는 반복문을 중지하고, 반복문을 빠져 나옴.
break

6
boj/10952.py Normal file
View File

@@ -0,0 +1,6 @@
while True:
a,b=map(int,input().split())
if a==b==0:
break
print(a+b)

5
boj/11021.py Normal file
View File

@@ -0,0 +1,5 @@
n=int(input())
for i in range(n):
a,b=map(int,input().split())
print("Case #"+str(i+1)+":",a+b)

5
boj/11022.py Normal file
View File

@@ -0,0 +1,5 @@
n=int(input())
for i in range(n):
a,b=map(int,input().split())
print("Case #"+str(i+1)+":",a,"+",b,"=",a+b)

14
boj/11047.py Normal file
View File

@@ -0,0 +1,14 @@
n,k=map(int,input().split())
oarr=[]
for i in range(n):
oarr.append(int(input()))
oarr.reverse()
count=0
for i in oarr:
d=int(k/i)
k-=(i*d)
count+=d
print(count)

15
boj/11279.py Normal file
View File

@@ -0,0 +1,15 @@
from sys import stdin
from queue import PriorityQueue
n=int(stdin.readline().rstrip())
q=PriorityQueue()
for _ in range(n):
i=int(stdin.readline().rstrip())
if i==0:
if q.qsize():
print(q.get()*(-1))
else:
print("0")
else:
q.put(-i)

16
boj/11286.py Normal file
View File

@@ -0,0 +1,16 @@
from sys import stdin
from queue import PriorityQueue
n=int(stdin.readline().rstrip())
pq=PriorityQueue()
for i in range(n):
inp=int(stdin.readline().rstrip())
if inp==0:
if pq.qsize()==0:
print(0)
else:
print(pq.get()[1])
else:
v=(abs(inp),inp)
pq.put(v)

13
boj/11399.py Normal file
View File

@@ -0,0 +1,13 @@
n=int(input())
arr=list(map(int,input().split()))
min=list()
arr.sort()
min.append(arr[0])
sum=arr[0]
for i in range(1,n):
min.append(min[i-1]+arr[i])
sum+=min[i]
print(sum)

18
boj/11501.py Normal file
View File

@@ -0,0 +1,18 @@
import sys
input=sys.stdin.readline
t=int(input().rstrip())
for _ in range(t):
d=int(input().rstrip())
arr=list(map(int,input().rstrip().split()))
mx=0
s=0
for i in range(d):
a=arr.pop()
if mx<a:
mx=a
else:
s+=(mx-a)
print(s)

28
boj/1157.py Normal file
View File

@@ -0,0 +1,28 @@
import sys
s=sys.stdin.readline().rstrip().upper()
cnt=dict()
for i in range(len(s)):
if not s[i] in cnt:
cnt[s[i]]=0
cnt[s[i]]+=1
# print(s[i],cnt[s[i]])
max=[0,'A',False]
for i in range(ord('A'),ord('a')):
k=chr(i)
if not k in cnt:
continue
else:
# print(cnt[k])
if max[0]<cnt[k]:
max[0]=cnt[k]
max[1]=k
max[2]=False
elif max[0]==cnt[k]:
max[2]=True
if max[2]==True:
print("?")
else:
print(max[1])

12
boj/11650.py Normal file
View File

@@ -0,0 +1,12 @@
from sys import stdin
n=int(stdin.readline().rstrip())
arr=[]
for _ in range(n):
a,b=map(int,stdin.readline().rstrip().split())
arr.append((a,b))
arr.sort(key=lambda x:(x[0],x[1]))
for i in arr:
print(i[0],i[1])

13
boj/11651.py Normal file
View File

@@ -0,0 +1,13 @@
from sys import stdin
n=int(stdin.readline().rstrip())
arr=[]
for _ in range(n):
x,y=map(int,stdin.readline().rstrip().split())
arr.append((x,y))
arr.sort(key=lambda x:(x[1],x[0]))
for i in arr:
print(*i)

12
boj/11659.py Normal file
View File

@@ -0,0 +1,12 @@
from sys import stdin
n,m=map(int,stdin.readline().rstrip().split())
arr=list(map(int,stdin.readline().rstrip().split()))
sarr=[]
sarr.append(arr[0])
for i in range(1,n):
sarr.append(sarr[i-1]+arr[i])
for i in range(m):
a,b=map(int,stdin.readline().rstrip().split())
print(sarr[b-1]-sarr[a-1]+arr[a-1])

5
boj/11718.py Normal file
View File

@@ -0,0 +1,5 @@
while True:
try:
print(input())
except EOFError:
break

8
boj/11720.py Normal file
View File

@@ -0,0 +1,8 @@
n=int(input())
str=input()
sum=0
for i in range(n):
sum+=int(str[i])
print(sum)

28
boj/11723.py Normal file
View File

@@ -0,0 +1,28 @@
import sys
n=int(sys.stdin.readline().rstrip())
arr=set()
for _ in range(n):
com=sys.stdin.readline().rstrip().split()
if len(com)==1:
if com[0]=="all":
arr=set([i for i in range(1,21)])
else:
arr.clear()
else:
num=int(com[1])
if com[0]=="add":
arr.add(num)
elif com[0]=="remove":
arr.discard(num)
elif com[0]=="check":
if num in arr:
print(1)
else:
print(0)
elif com[0]=="toggle":
if num in arr:
arr.discard(num)
else:
arr.add(num)

7
boj/11726.py Normal file
View File

@@ -0,0 +1,7 @@
n=int(input())
arr=[0,1,2,3]
for i in range(4,n+1):
arr.append(arr[i-1]+arr[i-2])
print(arr[n]%10007)

25
boj/1181.py Normal file
View File

@@ -0,0 +1,25 @@
# 데이터 개수(n)을 입력받음.
n=int(input())
# 데이터를 입력받아 쌓아둘 배열(리스트) 선언 및 초기화
iarr=[]
# 데이터 개수만큼 반복하여 데이터 받음.
for i in range(n):
iarr.append(input())
# 새 배열 변수 선언 및 초기화 - set형을 사용하여 기존 입력받은 배열 변환 : 중복 값 제거
arr=list(set(iarr))
# print(type(arr))
# print(arr)
# 배열 요소를 알파벳 순서대로 정렬
arr.sort()
# print(arr)
# 정렬된 배열 요소를 다시 길이 순서대로 정렬
arr.sort(key=len)
# print(arr)
# 출력 - 실제 정렬된 배열 요소 개수만큼 반복하여 출력
for i in range(len(arr)):
print(arr[i])

30
boj/11866.py Normal file
View File

@@ -0,0 +1,30 @@
from sys import stdin
n,k=map(int,stdin.readline().rstrip().split())
arr=[]
sarr=set()
i=k
cnt=k
while True:
if i>n:
i-=n
if i in sarr:
i+=1
continue
elif cnt%k==0:
arr.append(i)
sarr.add(i)
i+=1
cnt+=1
if len(arr)==n:
break
print("<",end="")
for i in range(n):
print(arr[i],end="")
if i<n-1:
print(", ",end="")
print(">")

65
boj/1260.py Normal file
View File

@@ -0,0 +1,65 @@
# n=정점 수, m=간선 수, v=시작점
n,m,v=map(int,input().split())
# 정점에 연결되는 간선을 넣을 이중 리스트(배열)
node=[[0]*n for _ in range(n)]
# 각 DFS, BFS 결과를 넣을 리스트
dfs=[]
bfs=[]
# 간선을 입력 받음
for _ in range(m):
a,b=map(int,input().split())
# 해당 문제는 무방향(양방향) 그래프이므로, 양쪽 간선 배열에 모두 연결되었음을 표시해야 함.
node[a-1][b-1]=node[b-1][a-1]=1
# - DFS 구현
# 방문 여부를 담을 리스트를 모두 0으로 초기화
visit=[0 for _ in range(n)]
# 재귀를 이용하여 구현하기 위해 함수 선언
def dfs_fun(now):
# 방문한 정점을 리스트에 추가하고, 방문 여부를 표시
dfs.append(now+1)
visit[now]=1
# 다음 정점 방문을 위해 반복
for i in range(n):
# 만약, 연결된 간선 중에 아직 방문하지 않은 정점이 있는 경우, 해당 정점을 방문하기 위해 재귀 실행
if node[now][i]==1 and visit[i]==0:
dfs_fun(i)
# DFS 탐색 시작점을 정의
start=v-1
# DFS 재귀 탐색 함수 호출
dfs_fun(start)
# - BFS 구현
# 첫 방문할 시작점을 정의
now=v-1
# 방문 여부를 담을 리스트를 0으로 초기화
visit=[0 for _ in range(n)]
# 현재 방문한 위치는 이미 방문한 것으로 함.
visit[now]=1
# 방문할 정점을 담을 리스트 변수 선언(큐 형태로 사용)
queue=[]
# 현재 방문한 위치는 큐에 추가
queue.append(now)
# BFS 탐색 시작
while len(queue)>0:
# 현재 탐색 위치는 큐에서 빼오고, 방문한 정점 추가
now=queue.pop(0)
bfs.append(now+1)
# 다음 방문 위치를 큐에 추가하기 위해 반복
for i in range(n):
# 간선이 연결되어있지만, 아직 방문하지 않은 정점은 큐에 추가하여 다음에 방문할 수 있도록 함.
if node[now][i]==1 and visit[i]==0:
visit[i]=1
queue.append(i)
# 결과 출력 (DFS, BFS 순)
for i in range(len(dfs)):
print(dfs[i],end=" ")
print() # 줄바꿈을 위한 빈 print 함수 실행
for i in range(len(bfs)):
print(bfs[i],end=" ")

16
boj/12904.py Normal file
View File

@@ -0,0 +1,16 @@
import sys
input=sys.stdin.readline
a=input().rstrip()
b=input().rstrip()
bl=list(b)
while len(a)<len(bl):
c=bl.pop()
if c=='B':
bl.reverse()
if a==''.join(bl):
print(1)
else:
print(0)

8
boj/1330.py Normal file
View File

@@ -0,0 +1,8 @@
a,b=map(int,input().split())
if a>b:
print(">")
elif a<b:
print("<")
else:
print("==")

24
boj/1459.py Normal file
View File

@@ -0,0 +1,24 @@
import sys
input=sys.stdin.readline
x,y,tw,ts=map(int,input().rstrip().split())
tw2=tw*2
ts2=ts*2
sum=0
minxy=min(x,y)
if minxy>0:
sum+=(min(ts,tw2)*minxy)
x-=minxy
y-=minxy
maxxy=max(x,y)
if maxxy>0:
if (maxxy%2)==0:
sum+=(min(ts2,tw2)*int(maxxy/2))
elif maxxy>2:
sum+=(min(ts2,tw2)*int(maxxy/2)+tw)
else:
sum+=tw
print(sum)

11
boj/14681.py Normal file
View File

@@ -0,0 +1,11 @@
x=int(input())
y=int(input())
if x>=0 and y>=0:
print(1)
elif x<0 and y>=0:
print(2)
elif x<0 and y<0:
print(3)
else:
print(4)

11
boj/14916.py Normal file
View File

@@ -0,0 +1,11 @@
n=int(input())
count=0
while n>0 and not n%5==0:
count+=1
n-=2
if n>-1 and n%5==0:
print((n//5)+count)
else:
print(-1)

41
boj/14940.py Normal file
View File

@@ -0,0 +1,41 @@
from sys import stdin
n,m=map(int,stdin.readline().rstrip().split())
inmap=[[0]*m for _ in range(n)]
visit=[[-1]*m for _ in range(n)]
sx=sy=0
for i in range(n):
s=list(map(int,stdin.readline().rstrip().split()))
for j in range(m):
if s[j]==2:
sx=i
sy=j
elif s[j]==0:
visit[i][j]=0
inmap[i][j]=s[j]
dx=[1,0,-1,0]
dy=[0,1,0,-1]
next=[]
next.append((sx,sy))
visit[sx][sy]=0
while len(next)>0:
now=next.pop(0)
i=now[0]
j=now[1]
for a in range(4):
ddx=i+dx[a]
ddy=j+dy[a]
if ddx==-1 or ddx==n or ddy==-1 or ddy==m:
continue
if inmap[ddx][ddy]==1 and visit[ddx][ddy]<=0:
next.append((ddx,ddy))
visit[ddx][ddy]=visit[i][j]+1
for i in range(n):
for j in range(m):
print(visit[i][j],end=" ")
print()

7
boj/15552.py Normal file
View File

@@ -0,0 +1,7 @@
import sys
n=int(sys.stdin.readline().rstrip())
for _ in range(n):
a,b=map(int,sys.stdin.readline().rstrip().split())
print(a+b)

18
boj/15649.py Normal file
View File

@@ -0,0 +1,18 @@
n,m=map(int,input().split())
arr=[]
ch=[0]*(n+1)
def bt():
if len(arr)==m:
print(*arr)
return
for i in range(1,n+1):
if ch[i]==1:
continue
arr.append(i)
ch[i]=1
bt()
ch[arr.pop()]=0
bt()

18
boj/15650.py Normal file
View File

@@ -0,0 +1,18 @@
n,m=map(int,input().split())
arr=[]
ch=[0]*(n+1)
def bt(s):
if len(arr)==m:
print(*arr)
return
for i in range(s,n+1):
if ch[i]==1:
continue
arr.append(i)
ch[i]=1
bt(i)
ch[arr.pop()]=0
bt(1)

14
boj/15651.py Normal file
View File

@@ -0,0 +1,14 @@
n,m=map(int,input().split())
arr=[]
def bt():
if len(arr)==m:
print(*arr)
return
for i in range(1,n+1):
arr.append(i)
bt()
arr.pop()
bt()

14
boj/15652.py Normal file
View File

@@ -0,0 +1,14 @@
n,m=map(int,input().split())
arr=[]
def bt(s):
if len(arr)==m:
print(*arr)
return
for i in range(s,n+1):
arr.append(i)
bt(i)
arr.pop()
bt(1)

20
boj/15654.py Normal file
View File

@@ -0,0 +1,20 @@
n,m=map(int,input().split())
inarr=list(map(int,input().split()))
arr=[]
inarr.sort()
def bt():
if len(arr)==m:
print(*arr)
return
for i in inarr:
if i in arr:
continue
arr.append(i)
bt()
arr.pop()
bt()

20
boj/15655.py Normal file
View File

@@ -0,0 +1,20 @@
n,m=map(int,input().split())
inarr=list(map(int,input().split()))
arr=[]
inarr.sort()
def bt(s):
if len(arr)==m:
print(*arr)
return
for i in range(s,n):
v=inarr[i]
if v in arr:
continue
arr.append(v)
bt(i)
arr.pop()
bt(0)

17
boj/15656.py Normal file
View File

@@ -0,0 +1,17 @@
n,m=map(int,input().split())
inarr=list(map(int,input().split()))
arr=[]
inarr.sort()
def bt():
if len(arr)==m:
print(*arr)
return
for i in inarr:
arr.append(i)
bt()
arr.pop()
bt()

17
boj/15657.py Normal file
View File

@@ -0,0 +1,17 @@
n,m=map(int,input().split())
inarr=list(map(int,input().split()))
arr=[]
inarr.sort()
def bt(p):
if len(arr)==m:
print(*arr)
return
for i in range(p,n):
arr.append(inarr[i])
bt(i)
arr.pop()
bt(0)

23
boj/15663.py Normal file
View File

@@ -0,0 +1,23 @@
n,m=map(int,input().split())
inarr=list(map(int,input().split()))
arr=[]
ch=[False]*n
inarr.sort()
def bt():
if len(arr)==m:
print(*arr)
return
l=0
for i in range(n):
if not ch[i] and l!=inarr[i]:
ch[i]=True
l=inarr[i]
arr.append(l)
bt()
ch[i]=False
arr.pop()
bt()

23
boj/15664.py Normal file
View File

@@ -0,0 +1,23 @@
n,m=map(int,input().split())
inarr=list(map(int,input().split()))
arr=[]
ch=[False]*n
inarr.sort()
def bt(s):
if len(arr)==m:
print(*arr)
return
l=0
for i in range(s,n):
if not ch[i] and l!=inarr[i]:
ch[i]=True
arr.append(inarr[i])
bt(i)
arr.pop()
ch[i]=False
l=inarr[i]
bt(0)

20
boj/15665.py Normal file
View File

@@ -0,0 +1,20 @@
n,m=map(int,input().split())
inarr=sorted(list(map(int,input().split())))
arr=[]
def bt():
if len(arr)==m:
print(*arr)
return
l=0
for i in inarr:
if i==l:
continue
arr.append(i)
bt()
arr.pop()
l=i
bt()

15
boj/1620.py Normal file
View File

@@ -0,0 +1,15 @@
import sys
n,m=map(int,sys.stdin.readline().rstrip().split())
dic1=dict()
dic2=dict()
for i in range(1,n+1):
dic1[i]=sys.stdin.readline().rstrip()
dic2[dic1[i]]=i
for _ in range(m):
s=sys.stdin.readline().rstrip()
try:
print(dic1.get(int(s)))
except:
print(dic2.get(s))

27
boj/1654.py Normal file
View File

@@ -0,0 +1,27 @@
from sys import stdin
k,n=map(int,stdin.readline().rstrip().split())
max=0
arr=[]
for _ in range(k):
a=int(stdin.readline().rstrip())
arr.append(a)
if a>max:
max=a
l=1
r=max
while l<=r:
count=0
m=(l+r)//2
for i in range(k):
count+=arr[i]//m
if count<n:
r=m-1
else:
l=m+1
print(r)

17
boj/1676.py Normal file
View File

@@ -0,0 +1,17 @@
n=int(input())
p=1
for i in range(2,n+1):
p*=i
res=str(p).split('0')
count=0
a=1
while True:
if res=="" or not res[-a]=='':
break
count+=1
a+=1
print(count)

10
boj/17219.py Normal file
View File

@@ -0,0 +1,10 @@
import sys
n,m=map(int,sys.stdin.readline().rstrip().split())
acc=dict()
for _ in range(n):
s1,s2=map(str,sys.stdin.readline().rstrip().split())
acc[s1]=s2
for _ in range(m):
s=sys.stdin.readline().rstrip()
print(acc.get(s))

20
boj/1764.py Normal file
View File

@@ -0,0 +1,20 @@
from sys import stdin
n,m=map(int,stdin.readline().rstrip().split())
noarr=set()
for _ in range(n):
s=stdin.readline().rstrip()
noarr.add(s)
carr=[]
for _ in range(m):
s=stdin.readline().rstrip()
if s in noarr:
carr.append(s)
carr.sort()
print(len(carr))
for i in carr:
print(i)

9
boj/1789.py Normal file
View File

@@ -0,0 +1,9 @@
s=int(input())
count=1
sum=1
while sum<=s:
count+=1
sum+=count
print(count-1)

1
boj/18108.py Normal file
View File

@@ -0,0 +1 @@
print(int(input())-543)

34
boj/18110.py Normal file
View File

@@ -0,0 +1,34 @@
from sys import stdin
# 파이썬 내 반올림 함수(round)의 '오사오입' 방식이 아닌 일반 '사사오입' 방식의 결과를 도출하기 위해 별도의 함수 정의
# 공식 : round(<대상 값>+10^(-<대상 값의 길이>-1))
# => 예시 : (대상=3.5) => 3.5+10^(-3-1) = 3.5+10^-4 = 3.5+0.0001 = 3.5001
def round_func(value):
return round(value+10**(-len(str(value))-1))
n=int(stdin.readline().rstrip())
res=0
# 데이터의 갯수가 0(없음)일 수도 있으므로 0인지 검증
if n>0:
arr=[]
sum=0
for _ in range(n):
a=int(stdin.readline().rstrip())
arr.append(a)
sum+=a
arr.sort()
# 제외해야하는 범위 산출 - 반올림 필요
b=round_func(n*0.15)
# 제외된 범위의 합계를 저장할 변수
bsum=0
for i in range(b):
# 리스트는 정렬 상태이므로, 앞쪽에는 최소, 뒤쪽에는 최대 값이 들어있게 됨.
# 제외 범위 앞쪽과 뒤쪽의 값을 더하여 합계 변수에 더함.
bsum+=(arr[i]+arr[-i-1])
# 결과 값 계산(총합에서 범위 외 합계 제외, 개수 또한 제외) - 반올림 필요
res=round_func((sum-bsum)/(n-b*2))
print(res)

12
boj/18870.py Normal file
View File

@@ -0,0 +1,12 @@
from sys import stdin
n=int(stdin.readline().rstrip())
arr=list(map(int,stdin.readline().rstrip().split()))
sarr=sorted(set(arr))
carr=dict()
for i in range(len(sarr)-1,-1,-1):
j=sarr.pop()
carr[j]=i
for i in arr:
print(carr[i],end=" ")

12
boj/1920.py Normal file
View File

@@ -0,0 +1,12 @@
from sys import stdin
n=int(stdin.readline().rstrip())
a=set(map(int,stdin.readline().rstrip().split()))
m=int(stdin.readline().rstrip())
b=list(map(int,stdin.readline().rstrip().split()))
for i in range(m):
if b[i] in a:
print(1)
else:
print(0)

19
boj/1927.py Normal file
View File

@@ -0,0 +1,19 @@
from sys import stdin
from queue import PriorityQueue
n=int(stdin.readline().rstrip())
# 원래 set을 사용하여 구현하려고 했었는데, 만약, 데이터 중에서 중복 값이 있는 경우, 중복 값이 제거되어서는 안되므로 정답으로 인정되지 않을 가능성을 고려하여 사용하지 않음.
# l=set()
# 우선순위 큐 객체 생성
q=PriorityQueue()
for _ in range(n):
i=int(stdin.readline().rstrip())
if i==0:
if q.qsize()>0:
print(q.get())
else:
print("0")
else:
q.put(i)

16
boj/1931.py Normal file
View File

@@ -0,0 +1,16 @@
n=int(input())
arr=[]
for _ in range(n):
arr.append(tuple(map(int,input().split())))
arr.sort(key=lambda x:(x[1],x[0]))
last=0
count=0
for i in arr:
if i[0] >= last:
count+=1
last=i[1]
print(count)

33
boj/1966.py Normal file
View File

@@ -0,0 +1,33 @@
from sys import stdin
t=int(stdin.readline().rstrip())
for _ in range(t):
n,m=map(int,stdin.readline().rstrip().split())
tarr=list(map(int,stdin.readline().rstrip().split()))
arr=[]
q=[]
for i in range(n):
arr.append((tarr[i],i))
q.append(arr[i])
arr.sort(key=lambda x:-x[0])
i=0
cnt=0
next=arr.pop(0)
while True:
now=q.pop(0)
if now[0]==next[0]:
if len(arr)>0:
next=arr.pop(0)
cnt+=1
else:
q.append(now)
continue
if now[1]==m:
break
print(cnt)

15
boj/2075.py Normal file
View File

@@ -0,0 +1,15 @@
from sys import stdin
import heapq
n=int(stdin.readline().rstrip())
hq=[]
for _ in range(n):
a=list(map(int,stdin.readline().rstrip().split()))
for i in a:
if len(hq)<=n or i>hq[0]:
heapq.heappush(hq,i)
if len(hq)>n:
heapq.heappop(hq)
print(heapq.heappop(hq))

42
boj/21736.py Normal file
View File

@@ -0,0 +1,42 @@
from sys import stdin
from collections import deque
n,m=map(int,stdin.readline().rstrip().split())
arr=[['']*m for _ in range(n)]
sx=sy=0
for i in range(n):
li=stdin.readline().rstrip()
for j in range(m):
arr[i][j]=li[j]
if li[j]=='I':
sx=i
sy=j
dx=[1,0,-1,0]
dy=[0,1,0,-1]
cnt=0
next=deque()
next.append((sx,sy))
arr[sx][sy]='C'
while next:
now=next.pop()
for i in range(4):
ddx=now[0]+dx[i]
ddy=now[1]+dy[i]
if ddx<0 or ddy<0 or ddx>=n or ddy>=m:
continue
c=arr[ddx][ddy]
if c=='O' or c=='P':
if c=='P':
cnt+=1
next.append((ddx,ddy))
arr[ddx][ddy]='C'
if cnt==0:
print('TT')
else:
print(cnt)

35
boj/2178.py Normal file
View File

@@ -0,0 +1,35 @@
from sys import stdin
from collections import deque # deque 사용 연습 겸
n,m=map(int,stdin.readline().rstrip().split())
arr=[[0]*m for _ in range(n)]
for i in range(n):
s=stdin.readline().rstrip()
for j in range(m):
arr[i][j]=int(s[j])
dx=[1,0,-1,0]
dy=[0,1,0,-1]
i=j=0
next=deque()
visit=[[0]*m for _ in range(n)]
next.append((i,j))
visit[i][j]=1
while len(next):
now=next.popleft()
i=now[0]
j=now[1]
for a in range(4):
ddx=i+dx[a]
ddy=j+dy[a]
if ddx==-1 or ddx==n or ddy==-1 or ddy==m:
continue
if arr[ddx][ddy]==1 and visit[ddx][ddy]<=0:
next.append((ddx,ddy))
visit[ddx][ddy]=visit[i][j]+1
print(visit[n-1][m-1])

44
boj/24060.py Normal file
View File

@@ -0,0 +1,44 @@
import sys
n,k=map(int,sys.stdin.readline().rstrip().split())
oarr=list(map(int,sys.stdin.readline().rstrip().split()))
karr=[]
def merge_sort(l,r):
if l<r:
q=int((l+r)/2)
merge_sort(l,q)
merge_sort(q+1,r)
merge(l,q,r)
def merge(l,q,r):
tarr=[]
i=l
j=q+1
while i<=q and j<=r:
if oarr[i]<oarr[j]:
tarr.append(oarr[i])
karr.append(oarr[i])
i+=1
else:
tarr.append(oarr[j])
karr.append(oarr[j])
j+=1
while i<=q:
tarr.append(oarr[i])
karr.append(oarr[i])
i+=1
while j<=r:
tarr.append(oarr[j])
karr.append(oarr[j])
j+=1
for t in range(len(tarr)):
oarr[t+l]=tarr[t]
merge_sort(0,n-1)
if len(karr)<k:
print(-1)
else:
print(karr[k-1])

9
boj/2438.py Normal file
View File

@@ -0,0 +1,9 @@
a=int(input())
for i in range(1,a+1):
print("*"*i)
# for i in range(a):
# for _ in range(i+1):
# print("*",end="")
# print()

4
boj/2439.py Normal file
View File

@@ -0,0 +1,4 @@
n=int(input())
for i in range(1,n+1):
print("".rjust((n-i)," ")+("*"*i))

12
boj/2525.py Normal file
View File

@@ -0,0 +1,12 @@
h,m=map(int,input().split())
w=int(input())
m+=w
if m>=60:
wh=int(m/60)
h+=wh
if h>23:
h-=24
m-=wh*60
print(h,m)

12
boj/25304.py Normal file
View File

@@ -0,0 +1,12 @@
x=int(input())
n=int(input())
sum=0
for _ in range(n):
a,b=map(int,input().split())
sum+=a*b
if sum==x:
print("Yes")
else:
print("No")

10
boj/25314.py Normal file
View File

@@ -0,0 +1,10 @@
n=int(input())
# 1안
print("long "*(int(n/4)),end="")
print("int")
#2안
# for _ in range(int(n/4)):
# print("long",end=" ")
# print("int")

7
boj/2562.py Normal file
View File

@@ -0,0 +1,7 @@
arr=[]
for i in range(9):
arr.append([int(input()),i+1])
arr.sort()
print(arr[-1][0])
print(arr[-1][1])

38
boj/2568.py Normal file
View File

@@ -0,0 +1,38 @@
import bisect
from sys import stdin
input=stdin.readline
n=int(input())
arr=[]
for i in range(n):
inp=tuple(map(int,input().split()))
arr.append(inp)
arr.sort(key=lambda x:x[1])
l=[0]
lt=[(0,0)]
for i in arr:
a,b=i
if l[-1]<a:
l.append(a)
lt.append((a,len(l)-1))
else:
p=bisect.bisect_left(l,a)
l[p]=a
lt.append((a,p))
target=len(l)-1
darr=[]
for i in lt[::-1]:
if i[1]==target:
target-=1
else:
darr.append(i[0])
# print(darr)
darr.sort()
print(len(darr))
for i in darr:
print(i)

8
boj/2588.py Normal file
View File

@@ -0,0 +1,8 @@
a=int(input())
b1=b2=int(input())
for i in range(1,4):
print(a*(b2%10))
b2=int(b2/10)
print(a*b1)

29
boj/2606.py Normal file
View File

@@ -0,0 +1,29 @@
from sys import stdin
n=int(stdin.readline().rstrip())
m=int(stdin.readline().rstrip())
arr=[[0]*n for _ in range(n)]
for _ in range(m):
a,b=map(int,stdin.readline().rstrip().split())
a-=1
b-=1
arr[a][b]=arr[b][a]=1
visit=[0 for _ in range(n)]
visit[0]=1
next=[]
i=0
cnt=0
while True:
for j in range(n):
if visit[j]==0 and arr[i][j]==1:
cnt+=1
visit[j]=1
next.append(j)
if len(next)==0:
break
else:
i=next.pop()
print(cnt)

10
boj/2751.py Normal file
View File

@@ -0,0 +1,10 @@
from sys import stdin
n=int(stdin.readline().rstrip())
arr=[]
for _ in range(n):
arr.append(int(stdin.readline().rstrip()))
arr.sort()
for a in arr:
print(a)

6
boj/2753.py Normal file
View File

@@ -0,0 +1,6 @@
y=int(input())
if (y%4==0 and not y%100==0) or y%400==0:
print(1)
else:
print(0)

16
boj/2839.py Normal file
View File

@@ -0,0 +1,16 @@
from sys import stdin
n=int(stdin.readline().rstrip())
res=0
while n>0:
if n%5==0:
res+=n//5
break
n-=3
res+=1
if n==1 or n==2:
res=-1
break
print(res)

11
boj/2884.py Normal file
View File

@@ -0,0 +1,11 @@
h,m=map(int,input().split())
if m-45<0:
h-=1
if h<0:
h+=24
m+=-45+60
else:
m-=45
print(h,m)

18
boj/2885.py Normal file
View File

@@ -0,0 +1,18 @@
k=int(input())
n=1
while n<k:
n*=2
count=0
s=0
d=n
if not n==k:
while not s==k:
di=d//2
if s+di<=k:
s+=di
d/=2
count+=1
print(n,count)

21
boj/2960.py Normal file
View File

@@ -0,0 +1,21 @@
from sys import stdin
n,k=map(int,stdin.readline().rstrip().split())
arr=[False for i in range(n+1)]
cnt=[0,0,False]
for i in range(2,n+1):
for j in range(i,n+1,i):
if arr[j]==True:
continue
arr[j]=True
cnt[0]+=1
if cnt[0]==k:
cnt[1]=j
cnt[2]=True
break
if cnt[2]==True:
break
print(cnt[1])

24
boj/3273.py Normal file
View File

@@ -0,0 +1,24 @@
import sys
n=int(sys.stdin.readline().rstrip())
arr=list(map(int,sys.stdin.readline().rstrip().split()))
x=int(sys.stdin.readline().rstrip())
count=0
start=0
end=n-1
arr.sort()
while True:
if start==end:
break
res=arr[start]+arr[end]
if res==x:
count+=1
end-=1
elif res>x:
end-=1
else:
start+=1
print(count)

37
boj/4949.py Normal file
View File

@@ -0,0 +1,37 @@
from sys import stdin
while True:
s=stdin.readline().rstrip()
st=[]
if s=='.':
break
suc=True
for i in range(len(s)):
c=s[i]
if c=='(' or c=='{' or c=='[':
st.append(c)
elif c==')' or c=='}' or c==']':
if len(st)==0:
suc=False
break
p=st.pop()
if c==')' and not p=='(':
suc=False
break
elif c=='}' and not p=='{':
suc=False
break
elif c==']' and not p=='[':
suc=False
break
if len(st)>0:
suc=False
if suc:
print("yes")
else:
print("no")

48
boj/7662.py Normal file
View File

@@ -0,0 +1,48 @@
from sys import stdin
import heapq
n=int(stdin.readline().rstrip())
for a in range(n):
m=int(stdin.readline().rstrip())
maxh,minh=[],[]
isdel=dict()
cnt=0
for i in range(m):
s=list(map(str,stdin.readline().rstrip().split()))
v=int(s[1])
if s[0]=='I':
heapq.heappush(maxh,(-v,i))
heapq.heappush(minh,(v,i))
isdel[i]=True
cnt+=1
else:
if cnt>0:
if v==-1:
while minh and not isdel[minh[0][1]]:
heapq.heappop(minh)
d=heapq.heappop(minh)
else:
while maxh and not isdel[maxh[0][1]]:
heapq.heappop(maxh)
d=heapq.heappop(maxh)
# print(d[0],d[1])
isdel[d[1]]=False
cnt-=1
else:
continue
# print(maxh)
# print(minh)
while minh and not isdel[minh[0][1]]:
heapq.heappop(minh)
while maxh and not isdel[maxh[0][1]]:
heapq.heappop(maxh)
# print(maxh)
# print(minh)
if cnt>0:
print(-maxh[0][0],minh[0][0])
else:
print("EMPTY")

6
boj/8393.py Normal file
View File

@@ -0,0 +1,6 @@
n=int(input())
sum=0
for i in range(1,n+1):
sum+=i
print(sum)

11
boj/9095.py Normal file
View File

@@ -0,0 +1,11 @@
from sys import stdin
n=int(stdin.readline().rstrip())
for _ in range(n):
arr=[1,2,4]
i=int(stdin.readline().rstrip())-1
for j in range(3,i+1):
arr.append(arr[j-3]+arr[j-2]+arr[j-1])
print(arr[i])

9
boj/9461.py Normal file
View File

@@ -0,0 +1,9 @@
from sys import stdin
t=int(stdin.readline().rstrip())
for i in range(t):
n=int(stdin.readline().rstrip())
arr=[1,1,1]
for j in range(3,n):
arr.append(arr[j-3]+arr[j-2])
print(arr[n-1])

12
boj/9498.py Normal file
View File

@@ -0,0 +1,12 @@
a=int(input())
if a>=90:
print("A")
elif a>=80:
print("B")
elif a>=70:
print("C")
elif a>=60:
print("D")
else:
print("F")