commit 2600340c03023498d048e9824161fdafe53771c8 Author: Gyubin Han <89185979+Gyubin-Han@users.noreply.github.com> Date: Tue Apr 30 16:59:10 2024 +0900 first commit from old repository to a new repository diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4422858 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.temp \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4541b11 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# PPS diff --git a/boj/1003.py b/boj/1003.py new file mode 100644 index 0000000..0093315 --- /dev/null +++ b/boj/1003.py @@ -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]) \ No newline at end of file diff --git a/boj/1032.py b/boj/1032.py new file mode 100644 index 0000000..49f9449 --- /dev/null +++ b/boj/1032.py @@ -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) \ No newline at end of file diff --git a/boj/10807.py b/boj/10807.py new file mode 100644 index 0000000..d3dd717 --- /dev/null +++ b/boj/10807.py @@ -0,0 +1,5 @@ +n=int(input()) +arr=list(map(int,input().split())) +s=int(input()) + +print(arr.count(s)) \ No newline at end of file diff --git a/boj/10814.py b/boj/10814.py new file mode 100644 index 0000000..a60e816 --- /dev/null +++ b/boj/10814.py @@ -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]) diff --git a/boj/10815.py b/boj/10815.py new file mode 100644 index 0000000..1b14e20 --- /dev/null +++ b/boj/10815.py @@ -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=" ") \ No newline at end of file diff --git a/boj/10816.py b/boj/10816.py new file mode 100644 index 0000000..ab77ae1 --- /dev/null +++ b/boj/10816.py @@ -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=" ") \ No newline at end of file diff --git a/boj/10818.py b/boj/10818.py new file mode 100644 index 0000000..08c684a --- /dev/null +++ b/boj/10818.py @@ -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]) \ No newline at end of file diff --git a/boj/10828.py b/boj/10828.py new file mode 100644 index 0000000..baa1890 --- /dev/null +++ b/boj/10828.py @@ -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])) \ No newline at end of file diff --git a/boj/10845.py b/boj/10845.py new file mode 100644 index 0000000..834cb01 --- /dev/null +++ b/boj/10845.py @@ -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])) \ No newline at end of file diff --git a/boj/10866.py b/boj/10866.py new file mode 100644 index 0000000..5106b8e --- /dev/null +++ b/boj/10866.py @@ -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])) + \ No newline at end of file diff --git a/boj/10950.py b/boj/10950.py new file mode 100644 index 0000000..0b328ed --- /dev/null +++ b/boj/10950.py @@ -0,0 +1,5 @@ +n=int(input()) + +for _ in range(n): + a,b=map(int,input().split()) + print(a+b) \ No newline at end of file diff --git a/boj/10951.py b/boj/10951.py new file mode 100644 index 0000000..686dc80 --- /dev/null +++ b/boj/10951.py @@ -0,0 +1,10 @@ +# 별도의 입력 갯수를 정하지 않고 계속 입력받기 위해 while문 사용 +while True: + # EOF를 통해서 프로그램이 종료되는 구조임. + try: + a,b=map(int,input().split()) + print(a+b) + # EOF가 발생한 경우, EOFError라는 예외가 발생하여, 이 예외를 처리 + except EOFError: + # 상위에서 동작하는 반복문을 중지하고, 반복문을 빠져 나옴. + break \ No newline at end of file diff --git a/boj/10952.py b/boj/10952.py new file mode 100644 index 0000000..2bf4f5d --- /dev/null +++ b/boj/10952.py @@ -0,0 +1,6 @@ +while True: + a,b=map(int,input().split()) + + if a==b==0: + break + print(a+b) \ No newline at end of file diff --git a/boj/11021.py b/boj/11021.py new file mode 100644 index 0000000..358a0f7 --- /dev/null +++ b/boj/11021.py @@ -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) diff --git a/boj/11022.py b/boj/11022.py new file mode 100644 index 0000000..8f09bef --- /dev/null +++ b/boj/11022.py @@ -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) \ No newline at end of file diff --git a/boj/11047.py b/boj/11047.py new file mode 100644 index 0000000..2db5d23 --- /dev/null +++ b/boj/11047.py @@ -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) diff --git a/boj/11279.py b/boj/11279.py new file mode 100644 index 0000000..cae0e95 --- /dev/null +++ b/boj/11279.py @@ -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) diff --git a/boj/11286.py b/boj/11286.py new file mode 100644 index 0000000..6b7dc94 --- /dev/null +++ b/boj/11286.py @@ -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) \ No newline at end of file diff --git a/boj/11399.py b/boj/11399.py new file mode 100644 index 0000000..0e4da54 --- /dev/null +++ b/boj/11399.py @@ -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) \ No newline at end of file diff --git a/boj/11501.py b/boj/11501.py new file mode 100644 index 0000000..c15c7b2 --- /dev/null +++ b/boj/11501.py @@ -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 mxn: + 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") \ No newline at end of file diff --git a/boj/1260.py b/boj/1260.py new file mode 100644 index 0000000..a4dd1b5 --- /dev/null +++ b/boj/1260.py @@ -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=" ") \ No newline at end of file diff --git a/boj/12904.py b/boj/12904.py new file mode 100644 index 0000000..5ad5134 --- /dev/null +++ b/boj/12904.py @@ -0,0 +1,16 @@ +import sys + +input=sys.stdin.readline +a=input().rstrip() +b=input().rstrip() +bl=list(b) + +while len(a)b: + print(">") +elif a0: + 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) diff --git a/boj/14681.py b/boj/14681.py new file mode 100644 index 0000000..785305a --- /dev/null +++ b/boj/14681.py @@ -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) \ No newline at end of file diff --git a/boj/14916.py b/boj/14916.py new file mode 100644 index 0000000..e29f5fd --- /dev/null +++ b/boj/14916.py @@ -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) \ No newline at end of file diff --git a/boj/14940.py b/boj/14940.py new file mode 100644 index 0000000..f30924a --- /dev/null +++ b/boj/14940.py @@ -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() \ No newline at end of file diff --git a/boj/15552.py b/boj/15552.py new file mode 100644 index 0000000..f82ae25 --- /dev/null +++ b/boj/15552.py @@ -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) \ No newline at end of file diff --git a/boj/15649.py b/boj/15649.py new file mode 100644 index 0000000..5242f59 --- /dev/null +++ b/boj/15649.py @@ -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() \ No newline at end of file diff --git a/boj/15650.py b/boj/15650.py new file mode 100644 index 0000000..9db081e --- /dev/null +++ b/boj/15650.py @@ -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) \ No newline at end of file diff --git a/boj/15651.py b/boj/15651.py new file mode 100644 index 0000000..d49942f --- /dev/null +++ b/boj/15651.py @@ -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() \ No newline at end of file diff --git a/boj/15652.py b/boj/15652.py new file mode 100644 index 0000000..98551fc --- /dev/null +++ b/boj/15652.py @@ -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) \ No newline at end of file diff --git a/boj/15654.py b/boj/15654.py new file mode 100644 index 0000000..4e45b1b --- /dev/null +++ b/boj/15654.py @@ -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() \ No newline at end of file diff --git a/boj/15655.py b/boj/15655.py new file mode 100644 index 0000000..14b8fd7 --- /dev/null +++ b/boj/15655.py @@ -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) \ No newline at end of file diff --git a/boj/15656.py b/boj/15656.py new file mode 100644 index 0000000..80a0f0a --- /dev/null +++ b/boj/15656.py @@ -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() \ No newline at end of file diff --git a/boj/15657.py b/boj/15657.py new file mode 100644 index 0000000..1043309 --- /dev/null +++ b/boj/15657.py @@ -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) \ No newline at end of file diff --git a/boj/15663.py b/boj/15663.py new file mode 100644 index 0000000..c2bb6c2 --- /dev/null +++ b/boj/15663.py @@ -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() \ No newline at end of file diff --git a/boj/15664.py b/boj/15664.py new file mode 100644 index 0000000..145ea41 --- /dev/null +++ b/boj/15664.py @@ -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) \ No newline at end of file diff --git a/boj/15665.py b/boj/15665.py new file mode 100644 index 0000000..9b263c6 --- /dev/null +++ b/boj/15665.py @@ -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() \ No newline at end of file diff --git a/boj/1620.py b/boj/1620.py new file mode 100644 index 0000000..f338afd --- /dev/null +++ b/boj/1620.py @@ -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)) \ No newline at end of file diff --git a/boj/1654.py b/boj/1654.py new file mode 100644 index 0000000..66e95a4 --- /dev/null +++ b/boj/1654.py @@ -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+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) \ No newline at end of file diff --git a/boj/18870.py b/boj/18870.py new file mode 100644 index 0000000..c656c0d --- /dev/null +++ b/boj/18870.py @@ -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=" ") \ No newline at end of file diff --git a/boj/1920.py b/boj/1920.py new file mode 100644 index 0000000..ec6d913 --- /dev/null +++ b/boj/1920.py @@ -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) \ No newline at end of file diff --git a/boj/1927.py b/boj/1927.py new file mode 100644 index 0000000..6575d23 --- /dev/null +++ b/boj/1927.py @@ -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) \ No newline at end of file diff --git a/boj/1931.py b/boj/1931.py new file mode 100644 index 0000000..084dded --- /dev/null +++ b/boj/1931.py @@ -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) \ No newline at end of file diff --git a/boj/1966.py b/boj/1966.py new file mode 100644 index 0000000..027fbc6 --- /dev/null +++ b/boj/1966.py @@ -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) \ No newline at end of file diff --git a/boj/2075.py b/boj/2075.py new file mode 100644 index 0000000..839588d --- /dev/null +++ b/boj/2075.py @@ -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)) \ No newline at end of file diff --git a/boj/21736.py b/boj/21736.py new file mode 100644 index 0000000..cff3ca5 --- /dev/null +++ b/boj/21736.py @@ -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) \ No newline at end of file diff --git a/boj/2178.py b/boj/2178.py new file mode 100644 index 0000000..3e9333d --- /dev/null +++ b/boj/2178.py @@ -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]) \ No newline at end of file diff --git a/boj/24060.py b/boj/24060.py new file mode 100644 index 0000000..73c328b --- /dev/null +++ b/boj/24060.py @@ -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=60: + wh=int(m/60) + h+=wh + if h>23: + h-=24 + m-=wh*60 + +print(h,m) \ No newline at end of file diff --git a/boj/25304.py b/boj/25304.py new file mode 100644 index 0000000..bc28be7 --- /dev/null +++ b/boj/25304.py @@ -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") \ No newline at end of file diff --git a/boj/25314.py b/boj/25314.py new file mode 100644 index 0000000..0be3502 --- /dev/null +++ b/boj/25314.py @@ -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") \ No newline at end of file diff --git a/boj/2562.py b/boj/2562.py new file mode 100644 index 0000000..3f0e489 --- /dev/null +++ b/boj/2562.py @@ -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]) \ No newline at end of file diff --git a/boj/2568.py b/boj/2568.py new file mode 100644 index 0000000..0a309f8 --- /dev/null +++ b/boj/2568.py @@ -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]0: + if n%5==0: + res+=n//5 + break + n-=3 + res+=1 + + if n==1 or n==2: + res=-1 + break + +print(res) \ No newline at end of file diff --git a/boj/2884.py b/boj/2884.py new file mode 100644 index 0000000..5c2fa77 --- /dev/null +++ b/boj/2884.py @@ -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) \ No newline at end of file diff --git a/boj/2885.py b/boj/2885.py new file mode 100644 index 0000000..e0fbaeb --- /dev/null +++ b/boj/2885.py @@ -0,0 +1,18 @@ +k=int(input()) +n=1 + +while nx: + end-=1 + else: + start+=1 + +print(count) \ No newline at end of file diff --git a/boj/4949.py b/boj/4949.py new file mode 100644 index 0000000..757aa6e --- /dev/null +++ b/boj/4949.py @@ -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") \ No newline at end of file diff --git a/boj/7662.py b/boj/7662.py new file mode 100644 index 0000000..4f90297 --- /dev/null +++ b/boj/7662.py @@ -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") \ No newline at end of file diff --git a/boj/8393.py b/boj/8393.py new file mode 100644 index 0000000..d3629f8 --- /dev/null +++ b/boj/8393.py @@ -0,0 +1,6 @@ +n=int(input()) +sum=0 + +for i in range(1,n+1): + sum+=i +print(sum) \ No newline at end of file diff --git a/boj/9095.py b/boj/9095.py new file mode 100644 index 0000000..1c9082c --- /dev/null +++ b/boj/9095.py @@ -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]) diff --git a/boj/9461.py b/boj/9461.py new file mode 100644 index 0000000..81d2bc1 --- /dev/null +++ b/boj/9461.py @@ -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]) \ No newline at end of file diff --git a/boj/9498.py b/boj/9498.py new file mode 100644 index 0000000..106914b --- /dev/null +++ b/boj/9498.py @@ -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") \ No newline at end of file diff --git a/swea/12368.py b/swea/12368.py new file mode 100644 index 0000000..06c7c5a --- /dev/null +++ b/swea/12368.py @@ -0,0 +1,9 @@ +n=int(input()) + +for i in range(n): + a,b=map(int,input().split()) + result=a+b + + if result>23: + result-=24 + print("#"+str(i+1),result) diff --git a/swea/1288.py b/swea/1288.py new file mode 100644 index 0000000..3344135 --- /dev/null +++ b/swea/1288.py @@ -0,0 +1,17 @@ +t=int(input()) + +for i in range(1,t+1): + n=int(input()) + + check=set() + x=1 + xn=0 + while True: + xn=x*n + for a in str(xn): + check.add(a) + + if len(check)==10: + break + x+=1 + print("#"+str(i),(x*n)) diff --git a/swea/1986.py b/swea/1986.py new file mode 100644 index 0000000..f6d2886 --- /dev/null +++ b/swea/1986.py @@ -0,0 +1,12 @@ +n=int(input()) + +for i in range(1,n+1): + k=int(input()) + + result=0 + for j in range(1,k+1): + if j%2==0: + result-=j + else: + result+=j + print("#"+str(i),result)