Skip to content

Commit

Permalink
알고리즘
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyeongchoi committed Mar 1, 2021
1 parent b620ae2 commit 6f312c0
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 0 deletions.
18 changes: 18 additions & 0 deletions argorithm/1003.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
T = int(input())
arr = [int(input()) for _ in range(T)]
def fibonacci(num):
global zero
global one
if num==0:
zero += 1
return 0
elif num==1:
one += 1
return 1
else:
return fibonacci(num-1)+fibonacci(num-2)
for a in arr:
zero = 0
one = 0
result = fibonacci(a)
print(zero, one)
18 changes: 18 additions & 0 deletions argorithm/1003_re.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
T = int(input())
arr = [int(input()) for _ in range(T)]

def fibonacci(num):
zero_cnt = [1, 0]
one_cnt = [0, 1]
if num <= 1:
return

for i in range(2, num+1):
zero_cnt.append(zero_cnt[i-1] + zero_cnt[i-2])
one_cnt.append(one_cnt[i-1] + one_cnt[i-2])
return zero_cnt, one_cnt

zero_cnt, one_cnt = fibonacci(40)

for a in arr:
print(zero_cnt[a], one_cnt[a])
30 changes: 30 additions & 0 deletions argorithm/1012.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline

def dfs(arr, visited, x, y):
dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

visited[x][y] = True
for i in range(4):
sx, sy = x+dx[i], y+dy[i]
if 0<=sx<n and 0<=sy<m and not visited[sx][sy] and arr[sx][sy]==1:
dfs(arr, visited, sx, sy)

t = int(input())
for _ in range(t):
m, n, k = map(int, input().split())
arr = [[0]*m for _ in range(n)]
for _ in range(k):
a, b = map(int, input().split())
arr[b][a]=1

answer = 0
visited = [[False]*m for _ in range(n)]
for x in range(n):
for y in range(m):
if not visited[x][y] and arr[x][y]==1:
dfs(arr, visited, x, y)
answer += 1
print(answer)
Empty file added argorithm/1463.py
Empty file.
29 changes: 29 additions & 0 deletions argorithm/ni_test1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def solution(A):
answer = ''

if A < 0:
A = str(abs(A))
A_list = list(str(abs(A)))

for i, n in enumerate(A_list):
if int(n) > 5:
answer+='5'
answer+=A[i:]
return int(answer)
else:
answer+=n
else:
A = str(A)
A_list = list(str(A))
for i, n in enumerate(A_list):
if int(n) < 5:
answer+='5'
answer+=A[i:]
return int(answer)
else:
answer+=n
return int(answer)

if __name__ == '__main__':
real_answer = solution(-999)
print(real_answer)
26 changes: 26 additions & 0 deletions argorithm/ni_test1_re.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
def solution(A):
A = list(str(A))
if '-' in A:
A = A[1:]
answer = ['-']
for i, a in enumerate(A):
if int(a) > 5:
answer += ['5']
answer += A[i:]
return int(''.join(answer))
else:
answer.append(a)
else:
answer = []
for i, a in enumerate(A):
if int(a) < 5:
answer.append('5')
answer+= A[i:]
return int(''.join(answer))
else:
answer.append(a)
return int(''.join(answer))

if __name__ == '__main__':
real_answer = solution(268)
print(real_answer)
10 changes: 10 additions & 0 deletions argorithm/ni_test2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def solution(A):
answer = []
A.sort()
for i in range(len(A)-1):
answer.append(abs(A[i]-A[i+1]))
return max(answer)//2

if __name__ == '__main__':
real_answer = solution([5, 5])
print(real_answer)
18 changes: 18 additions & 0 deletions argorithm/ni_test3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def solution(A):
answer = 0
temp = []
for i in range(len(A)-1):
temp.append(A[i]-A[i+1])

t1 = temp[0]
for j in enumerate(temp):
if t1==j:



return answer

if __name__ == '__main__':
real_answer = solution([-1,1,3,3,3,2,3,2,1,0])

print(real_answer)
34 changes: 34 additions & 0 deletions argorithm/sm1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
skill = input().split()
k = int(input())
relation = list(input().split() for _ in range(k))

temp = defaultdict(list)
for r in relation:
temp[r[0]] += r[1]

# while skill:
# s = skill.pop(0)
# if s in temp:
# for val in temp.values():
# if val in temp:

# else:
# print(s, val)


for t in temp:
for tval in temp[t]:
print(t, tval)
if tval in temp:
for val in temp[tval]:
print()



if __name__=="__main__":
main()
24 changes: 24 additions & 0 deletions argorithm/sm1_re.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
skill = input().split()
k = int(input())
relation = list(input().split() for _ in range(k))

min_val = min(len(s1), len(s2))
for i in range(min_val):
if s1[-i:] == s2[:i]:
answer.add(s1+s2[i:])

if s2[-i:] == s1[:i]:
answer.add(s2+s1[i:])
return min(sorted(answer), key=lambda x: len(x))




if __name__=="__main__":
main()

18 changes: 18 additions & 0 deletions argorithm/sm2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
p, n, h = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]

for i in range(1, p+1):
sumval = 0
for a in arr:
if a[0]==i and a[1]<=h:
sumval+=1000*a[1]
print(i, sumval)


if __name__=="__main__":
main()

0 comments on commit 6f312c0

Please sign in to comment.