diff --git a/1week/1000_A+B.py b/1week/1000_A+B.py new file mode 100644 index 0000000..0543132 --- /dev/null +++ b/1week/1000_A+B.py @@ -0,0 +1,2 @@ +a,b = map(int,input().split()) +print(a+b) \ No newline at end of file diff --git "a/1week/10818_\354\265\234\354\206\214,\354\265\234\353\214\200.py" "b/1week/10818_\354\265\234\354\206\214,\354\265\234\353\214\200.py" new file mode 100644 index 0000000..0e2f825 --- /dev/null +++ "b/1week/10818_\354\265\234\354\206\214,\354\265\234\353\214\200.py" @@ -0,0 +1,14 @@ +cnt = int(input()) +num_list = list(map(int,input().split())) + +min = num_list[0] +max = num_list[0] + +for i in range(cnt): + if maxnum_list[i]: + min = num_list[i] + +print(min,max) \ No newline at end of file diff --git a/1week/10950_A+B-3.py b/1week/10950_A+B-3.py new file mode 100644 index 0000000..0a102d7 --- /dev/null +++ b/1week/10950_A+B-3.py @@ -0,0 +1,4 @@ +T = int(input()) +for i in range(0,T): + a,b = map(int,input().split()) + print(a+b) \ No newline at end of file diff --git a/1week/10951-A+B-4.py b/1week/10951-A+B-4.py new file mode 100644 index 0000000..f3bc772 --- /dev/null +++ b/1week/10951-A+B-4.py @@ -0,0 +1,6 @@ +while True: + try: + A, B = map(int, input().split()) + print(A+B) + except: + break \ No newline at end of file diff --git a/1week/10952-A+B-5.py b/1week/10952-A+B-5.py new file mode 100644 index 0000000..84b7abd --- /dev/null +++ b/1week/10952-A+B-5.py @@ -0,0 +1,6 @@ +while True: + a, b = map(int, input().split()) + if a == 0 and b == 0: + break + else: + print(a+b) \ No newline at end of file diff --git a/1week/10953-A+B-6.py b/1week/10953-A+B-6.py new file mode 100644 index 0000000..006e934 --- /dev/null +++ b/1week/10953-A+B-6.py @@ -0,0 +1,5 @@ +T = int(input()) + +for i in range(T): + A,B = map(int,input().split(',')) + print(A+B) \ No newline at end of file diff --git "a/1week/10991-\353\263\204 \354\260\215\352\270\260-16.py" "b/1week/10991-\353\263\204 \354\260\215\352\270\260-16.py" new file mode 100644 index 0000000..2d7e249 --- /dev/null +++ "b/1week/10991-\353\263\204 \354\260\215\352\270\260-16.py" @@ -0,0 +1,3 @@ +n = int(input()) +for i in range(1,n+1): + print(" " * (n-i) + "* " * (i-1) + "*") \ No newline at end of file diff --git "a/1week/10992-\353\263\204 \354\260\215\352\270\260-17.py" "b/1week/10992-\353\263\204 \354\260\215\352\270\260-17.py" new file mode 100644 index 0000000..2d7e249 --- /dev/null +++ "b/1week/10992-\353\263\204 \354\260\215\352\270\260-17.py" @@ -0,0 +1,3 @@ +n = int(input()) +for i in range(1,n+1): + print(" " * (n-i) + "* " * (i-1) + "*") \ No newline at end of file diff --git a/1week/11021-A+B-7.py b/1week/11021-A+B-7.py new file mode 100644 index 0000000..702434e --- /dev/null +++ b/1week/11021-A+B-7.py @@ -0,0 +1,4 @@ +T = int(input()) +for i in range(1,T+1): + a,b = map(int,input().split()) + print('Case #'+str(i)+':',a+b) \ No newline at end of file diff --git a/1week/11022-A+B-8.py b/1week/11022-A+B-8.py new file mode 100644 index 0000000..9aa7082 --- /dev/null +++ b/1week/11022-A+B-8.py @@ -0,0 +1,5 @@ +T = int(input()) +for i in range(1,T+1): + a,b = map(int,input().split()) + print('Case #'+str(i)+':',a,'+',b,'=',a+b) + \ No newline at end of file diff --git "a/1week/11718-\352\267\270\353\214\200\353\241\234 \354\266\234\353\240\245\355\225\230\352\270\260.py" "b/1week/11718-\352\267\270\353\214\200\353\241\234 \354\266\234\353\240\245\355\225\230\352\270\260.py" new file mode 100644 index 0000000..22f3e89 --- /dev/null +++ "b/1week/11718-\352\267\270\353\214\200\353\241\234 \354\266\234\353\240\245\355\225\230\352\270\260.py" @@ -0,0 +1,8 @@ +while True: + try: + x = input() + if len(x) == 0 : + break + print(x) + except: + break \ No newline at end of file diff --git "a/1week/11719-\352\267\270\353\214\200\353\241\234 \354\266\234\353\240\245\355\225\230\352\270\2602.py" "b/1week/11719-\352\267\270\353\214\200\353\241\234 \354\266\234\353\240\245\355\225\230\352\270\2602.py" new file mode 100644 index 0000000..0c795b5 --- /dev/null +++ "b/1week/11719-\352\267\270\353\214\200\353\241\234 \354\266\234\353\240\245\355\225\230\352\270\2602.py" @@ -0,0 +1,6 @@ +while True: + try: + string = input() + print(string) + except: + break \ No newline at end of file diff --git "a/1week/11720-\354\210\253\354\236\220\354\235\230 \355\225\251.py" "b/1week/11720-\354\210\253\354\236\220\354\235\230 \355\225\251.py" new file mode 100644 index 0000000..e02ef6f --- /dev/null +++ "b/1week/11720-\354\210\253\354\236\220\354\235\230 \355\225\251.py" @@ -0,0 +1,4 @@ +num = input() +numbers = list(map(int,input())) + +print(sum(numbers)) \ No newline at end of file diff --git "a/1week/11721-\354\227\264 \352\260\234\354\224\251 \353\201\212\354\226\264 \354\266\234\353\240\245\355\225\230\352\270\260.py" "b/1week/11721-\354\227\264 \352\260\234\354\224\251 \353\201\212\354\226\264 \354\266\234\353\240\245\355\225\230\352\270\260.py" new file mode 100644 index 0000000..f9242b4 --- /dev/null +++ "b/1week/11721-\354\227\264 \352\260\234\354\224\251 \353\201\212\354\226\264 \354\266\234\353\240\245\355\225\230\352\270\260.py" @@ -0,0 +1,4 @@ +n=input() + +for i in range(0,len(n),10): + print(n[i:i+10]) \ No newline at end of file diff --git "a/1week/1924-2007\353\205\204.py" "b/1week/1924-2007\353\205\204.py" new file mode 100644 index 0000000..bc06a65 --- /dev/null +++ "b/1week/1924-2007\353\205\204.py" @@ -0,0 +1,12 @@ +day = 0 +month = [31,28,31,30,31,30,31,31,30,31,30,31] +week = ["SUN","MON","TUE","WED","THU","FRI","SAT"] + +x,y = map(int,input().split()) + +for i in range(x-1): + day += month[i] + +day = (day+y)%7 + +print(week[day]) \ No newline at end of file diff --git "a/1week/2438-\353\263\204 \354\260\215\352\270\260-1.py" "b/1week/2438-\353\263\204 \354\260\215\352\270\260-1.py" new file mode 100644 index 0000000..85b5647 --- /dev/null +++ "b/1week/2438-\353\263\204 \354\260\215\352\270\260-1.py" @@ -0,0 +1,4 @@ +cnt = int(input()) + +for i in range(1,cnt+1): + print("*"*i) \ No newline at end of file diff --git "a/1week/2439-\353\263\204 \354\260\215\352\270\260-2.py" "b/1week/2439-\353\263\204 \354\260\215\352\270\260-2.py" new file mode 100644 index 0000000..a01130b --- /dev/null +++ "b/1week/2439-\353\263\204 \354\260\215\352\270\260-2.py" @@ -0,0 +1,4 @@ +cnt = int(input()) + +for i in range(1,cnt+1): + print(' '*(cnt-i)+str('*')*i) \ No newline at end of file diff --git "a/1week/2440-\353\263\204 \354\260\215\352\270\260-3.py" "b/1week/2440-\353\263\204 \354\260\215\352\270\260-3.py" new file mode 100644 index 0000000..be5672c --- /dev/null +++ "b/1week/2440-\353\263\204 \354\260\215\352\270\260-3.py" @@ -0,0 +1,4 @@ +cnt = int(input()) + +for i in range(cnt,0,-1): + print('*'*i) \ No newline at end of file diff --git "a/1week/2441-\353\263\204 \354\260\215\352\270\260-4.py" "b/1week/2441-\353\263\204 \354\260\215\352\270\260-4.py" new file mode 100644 index 0000000..2f5fe14 --- /dev/null +++ "b/1week/2441-\353\263\204 \354\260\215\352\270\260-4.py" @@ -0,0 +1,3 @@ +cnt = int(input()) +for i in range(cnt,0,-1): + print(' '*(cnt-i)+str('*')*i) \ No newline at end of file diff --git "a/1week/2442-\353\263\204 \354\260\215\352\270\260-5.py" "b/1week/2442-\353\263\204 \354\260\215\352\270\260-5.py" new file mode 100644 index 0000000..5fa27bb --- /dev/null +++ "b/1week/2442-\353\263\204 \354\260\215\352\270\260-5.py" @@ -0,0 +1,4 @@ +cnt = int(input()) + +for i in range(1,cnt+1): + print(' '*(cnt-i)+str('*')*(2*i-1)) \ No newline at end of file diff --git "a/1week/2445-\353\263\204 \354\260\215\352\270\260-8.py" "b/1week/2445-\353\263\204 \354\260\215\352\270\260-8.py" new file mode 100644 index 0000000..39b89ff --- /dev/null +++ "b/1week/2445-\353\263\204 \354\260\215\352\270\260-8.py" @@ -0,0 +1,7 @@ +cnt = int(input()) + +for i in range(1,cnt+1): + print("*"*i+str(' ')*(2*cnt-2*i)+str('*')*i) + +for j in range(cnt-1,0,-1): + print('*'*j+str(' ')*(2*(cnt-j))+str('*')*j) \ No newline at end of file diff --git "a/1week/2446-\353\263\204 \354\260\215\352\270\260-9.py" "b/1week/2446-\353\263\204 \354\260\215\352\270\260-9.py" new file mode 100644 index 0000000..ef58e53 --- /dev/null +++ "b/1week/2446-\353\263\204 \354\260\215\352\270\260-9.py" @@ -0,0 +1,7 @@ +cnt = int(input()) + +for i in range(cnt,0,-1): + print(str(' ')*(cnt-i)+str('*')*(2*i-1)) + +for j in range(2,cnt+1): + print(str(' ')*(cnt-j)+str('*')*(2*j-1)) \ No newline at end of file diff --git "a/1week/2522-\353\263\204 \354\260\215\352\270\260-12.py" "b/1week/2522-\353\263\204 \354\260\215\352\270\260-12.py" new file mode 100644 index 0000000..9f1fcbe --- /dev/null +++ "b/1week/2522-\353\263\204 \354\260\215\352\270\260-12.py" @@ -0,0 +1,7 @@ +cnt = int(input()) + +for i in range(1,cnt+1): + print(' '*(cnt-i)+str('*')*i) + +for j in range(cnt-1,0,-1): + print(' '*(cnt-j)+str('*')*j) \ No newline at end of file diff --git a/1week/2557_Hello World.py b/1week/2557_Hello World.py new file mode 100644 index 0000000..1dc45ac --- /dev/null +++ b/1week/2557_Hello World.py @@ -0,0 +1 @@ +print("Hello World!") \ No newline at end of file diff --git a/1week/2558_A+B-2.py b/1week/2558_A+B-2.py new file mode 100644 index 0000000..2ae05f7 --- /dev/null +++ b/1week/2558_A+B-2.py @@ -0,0 +1,3 @@ +a = int(input()) +b = int(input()) +print(a+b) \ No newline at end of file diff --git "a/1week/2739-\352\265\254\352\265\254\353\213\250.py" "b/1week/2739-\352\265\254\352\265\254\353\213\250.py" new file mode 100644 index 0000000..0d4fe06 --- /dev/null +++ "b/1week/2739-\352\265\254\352\265\254\353\213\250.py" @@ -0,0 +1,3 @@ +i = int(input()) +for j in range(1,10): + print(i,'*',j,'=',i*j) \ No newline at end of file diff --git "a/1week/2741-N \354\260\215\352\270\260.py" "b/1week/2741-N \354\260\215\352\270\260.py" new file mode 100644 index 0000000..397aa27 --- /dev/null +++ "b/1week/2741-N \354\260\215\352\270\260.py" @@ -0,0 +1,3 @@ +num = int(input()) +for i in range(1,num+1): + print(i) diff --git "a/1week/2742-\352\270\260\354\260\215 N.py" "b/1week/2742-\352\270\260\354\260\215 N.py" new file mode 100644 index 0000000..2ca2aa0 --- /dev/null +++ "b/1week/2742-\352\270\260\354\260\215 N.py" @@ -0,0 +1,3 @@ +num = int(input()) +for i in range(num,0,-1): + print(i) diff --git "a/1week/8393-\355\225\251.py" "b/1week/8393-\355\225\251.py" new file mode 100644 index 0000000..a190058 --- /dev/null +++ "b/1week/8393-\355\225\251.py" @@ -0,0 +1,5 @@ +num = int(input()) +result = 0 +for i in range(1,num+1): + result = result + i +print(result) \ No newline at end of file diff --git "a/2week/1929-\354\206\214\354\210\230 \352\265\254\355\225\230\352\270\260.py" "b/2week/1929-\354\206\214\354\210\230 \352\265\254\355\225\230\352\270\260.py" new file mode 100644 index 0000000..1d08753 --- /dev/null +++ "b/2week/1929-\354\206\214\354\210\230 \352\265\254\355\225\230\352\270\260.py" @@ -0,0 +1,9 @@ +M,N = map(int,input().split()) +for i in range(M,N+1): #9 + if i ==1: + continue + for j in range(2,i): #2345678 + if i % j == 0: #9/2 + break + else: + print(i) diff --git "a/2week/1978-\354\206\214\354\210\230 \354\260\276\352\270\260.py" "b/2week/1978-\354\206\214\354\210\230 \354\260\276\352\270\260.py" new file mode 100644 index 0000000..4bec0de --- /dev/null +++ "b/2week/1978-\354\206\214\354\210\230 \354\260\276\352\270\260.py" @@ -0,0 +1,10 @@ +num = input() +M,N = map(int,input().split()) +for i in range(M,N+1): #9 + if i ==1: + continue + for j in range(2,i): #2345678 + if i % j == 0: #9/2 + break + else: + print(len(i)) diff --git "a/3week/10280-\354\212\244\355\203\235.py" "b/3week/10280-\354\212\244\355\203\235.py" new file mode 100644 index 0000000..4264920 --- /dev/null +++ "b/3week/10280-\354\212\244\355\203\235.py" @@ -0,0 +1,24 @@ +import sys +n = int(sys.stdin.readline()) + +stack = [] +for i in range(n): + command = sys.stdin.readline().split() + + if command[0] == 'push': + stack.append(command[1]) + + elif command[0] == 'pop': + if len(stack)==0: + print(-1) + else: + print(stack.pop()) + + elif command[0] == 'size': + print(len(stack)) + + elif command[0] == 'empty': + if len(stack)==0: + print(1) + else: + print(0) \ No newline at end of file diff --git "a/3week/10773-\354\240\234\353\241\234.py" "b/3week/10773-\354\240\234\353\241\234.py" new file mode 100644 index 0000000..d256944 --- /dev/null +++ "b/3week/10773-\354\240\234\353\241\234.py" @@ -0,0 +1,11 @@ +cnt = int(input()) +list = [] +for i in range(cnt): + num = int(input()) + if num == 0 : + list.pop() + else: + list.append(num) + + +print(sum(list)) \ No newline at end of file diff --git "a/3week/10845-\355\201\220.py" "b/3week/10845-\355\201\220.py" new file mode 100644 index 0000000..61c844b --- /dev/null +++ "b/3week/10845-\355\201\220.py" @@ -0,0 +1,30 @@ +import sys + +N = int(sys.stdin.readline()) + +queue = [] + +for i in range(N): + cmd = sys.stdin.readline().split() + + if cmd[0] == "push": + queue.insert(0, cmd[1]) + + elif cmd[0] == "pop": + if len(queue) != 0: print(queue.pop()) + else: print(-1) + + elif cmd[0] == "size": + print(len(queue)) + + elif cmd[0] == "empty": + if len(queue) == 0: print(1) + else : print(0) + + elif cmd[0] == "front": + if len(queue) == 0: print(-1) + else: print(queue[len(queue) -1]) + + elif cmd[0] == "back": + if len(queue) == 0: print(-1) + else: print(queue[0]) \ No newline at end of file diff --git "a/3week/10866-\353\215\261.py" "b/3week/10866-\353\215\261.py" new file mode 100644 index 0000000..e96cc9e --- /dev/null +++ "b/3week/10866-\353\215\261.py" @@ -0,0 +1,26 @@ +import sys +input = sys.stdin.readline + +n = int(input()) + +cmd = [input() for _ in range(n)] + +deque = [] + +for c in cmd: + if 'push_front' in c.split()[0]: + deque.insert(0, c.split()[1]) + elif 'push_back' in c.split()[0]: + deque.append(c.split()[1]) + elif 'pop_front' in c: + print(deque.pop(0)) if deque else print(-1) + elif 'pop_back' in c: + print(deque.pop(-1)) if deque else print(-1) + elif 'size' in c: + print(len(deque)) + elif 'empty' in c: + print(0) if deque else print(1) + elif 'front' in c: + print(deque[0]) if deque else print(-1) + elif 'back' in c: + print(deque[-1]) if deque else print(-1) diff --git "a/3week/11866-\354\232\224\354\204\270\355\221\270\354\212\244 \353\254\270\354\240\2340.py" "b/3week/11866-\354\232\224\354\204\270\355\221\270\354\212\244 \353\254\270\354\240\2340.py" new file mode 100644 index 0000000..1148ee0 --- /dev/null +++ "b/3week/11866-\354\232\224\354\204\270\355\221\270\354\212\244 \353\254\270\354\240\2340.py" @@ -0,0 +1,17 @@ +import sys +from collections import deque +n, k = map(int, sys.stdin.readline().split()) +d=deque() +res=[] +for i in range(1, n+1): + d.append(i) +while len(d)!=0: + for _ in range(k-1): + d.append(d.popleft()) + res.append(d.popleft()) +print('<', end='') +for i in range(len(res)): + if i==len(res)-1: + print(res[i],end='>') + else: + print(res[i], end=', ') \ No newline at end of file diff --git "a/3week/18258-\355\201\2202.py" "b/3week/18258-\355\201\2202.py" new file mode 100644 index 0000000..61c844b --- /dev/null +++ "b/3week/18258-\355\201\2202.py" @@ -0,0 +1,30 @@ +import sys + +N = int(sys.stdin.readline()) + +queue = [] + +for i in range(N): + cmd = sys.stdin.readline().split() + + if cmd[0] == "push": + queue.insert(0, cmd[1]) + + elif cmd[0] == "pop": + if len(queue) != 0: print(queue.pop()) + else: print(-1) + + elif cmd[0] == "size": + print(len(queue)) + + elif cmd[0] == "empty": + if len(queue) == 0: print(1) + else : print(0) + + elif cmd[0] == "front": + if len(queue) == 0: print(-1) + else: print(queue[len(queue) -1]) + + elif cmd[0] == "back": + if len(queue) == 0: print(-1) + else: print(queue[0]) \ No newline at end of file diff --git "a/3week/2164-\354\271\264\353\223\2342.py" "b/3week/2164-\354\271\264\353\223\2342.py" new file mode 100644 index 0000000..0be3aec --- /dev/null +++ "b/3week/2164-\354\271\264\353\223\2342.py" @@ -0,0 +1,14 @@ +nums = int(input()) +card = [] +ans = [] + +for i in range(1, nums+1): + card.append(i) + +while (len(card) != 0): + ans.append(card.pop(0)) + if(len(card) != 0): + card.append(card.pop(0)) + +for j in ans: + print(j, end =" ") \ No newline at end of file diff --git "a/3week/9012-\352\264\204\355\230\270.py" "b/3week/9012-\352\264\204\355\230\270.py" new file mode 100644 index 0000000..9f28a00 --- /dev/null +++ "b/3week/9012-\352\264\204\355\230\270.py" @@ -0,0 +1,19 @@ +T = int(input()) + +for i in range(T): + stack = [] + a=input() + for j in a: + if j == '(': + stack.append(j) + elif j == ')': + if stack: + stack.pop() + else: + print("NO") + break + else: + if not stack: + print("YES") + else: + print("NO") \ No newline at end of file diff --git "a/4week/10814-\353\202\230\354\235\264\354\210\234 \354\240\225\353\240\254.py" "b/4week/10814-\353\202\230\354\235\264\354\210\234 \354\240\225\353\240\254.py" new file mode 100644 index 0000000..e28e0a5 --- /dev/null +++ "b/4week/10814-\353\202\230\354\235\264\354\210\234 \354\240\225\353\240\254.py" @@ -0,0 +1,44 @@ +import sys +input = sys.stdin.readline +N = int(input()) + +# 2. member를 리스트로 입력받기 +# N번 반복하여 회원 정보를 입력받음 +# 각 줄은 공백으로 구분되므로, split()으로 나눔 +# 각 회원 정보는 [나이(str), 이름(str)] 형태로 리스트에 저장 +members = [list(map(str, input().split())) for _ in range(N)] + +# 3. 정렬하기 +# sort() 메서드를 사용하여 members 리스트를 정렬 +# key=lambda x: int(x[0])로 정렬 기준을 첫 번째 값(나이)으로 설정 +# x[0]은 문자열로 저장되므로 정수(int)로 변환하여 비교 +# Python의 sort()는 안정 정렬이므로, 나이가 같으면 입력 순서가 유지됨 +members.sort(key=lambda x: int(x[0])) + +# 4. 원하는 형식으로 출력하기 +# 정렬된 members 리스트에서 각 회원 정보를 출력 +# *member를 사용하여 리스트 요소를 공백으로 구분하여 출력 +for member in members: + print(*member) + +""" +num = int(input()) +mem_list = [] +for i in range(num): + mem = input().split() + mem[0] = int(mem[0]) # 첫 번째 값을 정수로 변환 + mem_list.append((mem, i)) # 데이터를 튜플로 저장: (데이터, 입력 순서) + +# 정렬 구현 +for i in range(len(mem_list)): + for j in range(i + 1, len(mem_list)): + if mem_list[i][0][0] > mem_list[j][0][0]: # 숫자가 더 큰 경우 + mem_list[i], mem_list[j] = mem_list[j], mem_list[i] + elif mem_list[i][0][0] == mem_list[j][0][0]: # 숫자가 같은 경우 + if mem_list[i][1] > mem_list[j][1]: # 입력 순서를 비교 + mem_list[i], mem_list[j] = mem_list[j], mem_list[i] + +# 결과 출력 +for item, _ in mem_list: + print(item) +""" \ No newline at end of file diff --git "a/4week/10870-\355\224\274\353\263\264\353\202\230\354\271\230 \354\210\2305.py" "b/4week/10870-\355\224\274\353\263\264\353\202\230\354\271\230 \354\210\2305.py" new file mode 100644 index 0000000..858d71c --- /dev/null +++ "b/4week/10870-\355\224\274\353\263\264\353\202\230\354\271\230 \354\210\2305.py" @@ -0,0 +1,7 @@ +num = int(input()) + +pivolist=[0,1] +for i in range(2,num+1): + pivolist.append(pivolist[i-2]+pivolist[i-1]) + +print(pivolist[num]) \ No newline at end of file diff --git "a/4week/10989-\354\210\230 \354\240\225\353\240\254\355\225\230\352\270\2603.py" "b/4week/10989-\354\210\230 \354\240\225\353\240\254\355\225\230\352\270\2603.py" new file mode 100644 index 0000000..79ad55c --- /dev/null +++ "b/4week/10989-\354\210\230 \354\240\225\353\240\254\355\225\230\352\270\2603.py" @@ -0,0 +1,29 @@ +import sys +input = sys.stdin.readline + +#계수정렬 활용 +n = int(input()) +arr = [0] * (10000 + 1) # 입력값이 10000개까지 주어지니 10000 + 1개의 리스트 선언 + +#각 입력값에 해당하는 인덱스의 값 증가 +for _ in range(n): + arr[int(input())] += 1 + +#arr에 기록된 정보 확인 +for i in range(len(arr)): + if arr[i] != 0: #0이 아닌 데이터, 즉 입력받은 데이터들을 출력 + for _ in range(arr[i]): + print(i) + + +''' 메모리 초과 +cnt = int(input()) +list=[] +for i in range(cnt): + num = int(input()) + list.append(num) + +sorted_list = sorted(list) +for j in sorted_list: + print(j) +''' \ No newline at end of file diff --git "a/4week/1427-\354\206\214\355\212\270\354\235\270\354\202\254\354\235\264\353\223\234.py" "b/4week/1427-\354\206\214\355\212\270\354\235\270\354\202\254\354\235\264\353\223\234.py" new file mode 100644 index 0000000..bd97a41 --- /dev/null +++ "b/4week/1427-\354\206\214\355\212\270\354\235\270\354\202\254\354\235\264\353\223\234.py" @@ -0,0 +1,11 @@ +n = int(input()) + +li = [] +for i in str(n): + li.append(int(i)) +# li = list(map(int,str(n))) + +li.sort(reverse=True) # 내림차순 + +for i in li: + print(i,end='') \ No newline at end of file diff --git "a/4week/17478-\354\236\254\352\267\200\355\225\250\354\210\230\352\260\200 \353\255\224\352\260\200\354\232\224.py" "b/4week/17478-\354\236\254\352\267\200\355\225\250\354\210\230\352\260\200 \353\255\224\352\260\200\354\232\224.py" new file mode 100644 index 0000000..4fb26b4 --- /dev/null +++ "b/4week/17478-\354\236\254\352\267\200\355\225\250\354\210\230\352\260\200 \353\255\224\352\260\200\354\232\224.py" @@ -0,0 +1,16 @@ +def chatbot(num, cnt): + print("____" * cnt + '"재귀함수가 뭔가요?"') + + if cnt == num: + print("____" * cnt + '"재귀함수는 자기 자신을 호출하는 함수라네"') + else: + print("____" * cnt + '"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.') + print("____" * cnt + "마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.") + print("____" * cnt + '그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어."') + chatbot(num, cnt + 1) + print("____" * cnt + "라고 답변하였지.") + + +num = int(input()) +print("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.") +chatbot(num, 0) \ No newline at end of file diff --git "a/4week/2750-\354\210\230 \354\240\225\353\240\254\355\225\230\352\270\260.py" "b/4week/2750-\354\210\230 \354\240\225\353\240\254\355\225\230\352\270\260.py" new file mode 100644 index 0000000..391dc27 --- /dev/null +++ "b/4week/2750-\354\210\230 \354\240\225\353\240\254\355\225\230\352\270\260.py" @@ -0,0 +1,12 @@ +cnt = int(input()) +list=[] +for i in range(cnt): + num = int(input()) + list.append(num) + +list.sort() #sort는 리스트를 제자리에서 정렬한다. 따라서 정렬 후 리스트를 직접 출력 +print(list) #바로 print(list.sort()) 하면 안되는 이유는 list.sort()는 리스트를 정렬하지만, 반환값이 none이기 때문 +#sorted_list = sorted(list) +#print(sorted_list) + + diff --git "a/4week/2947-\353\202\230\353\254\264\354\241\260\352\260\201.py" "b/4week/2947-\353\202\230\353\254\264\354\241\260\352\260\201.py" new file mode 100644 index 0000000..4bc29b6 --- /dev/null +++ "b/4week/2947-\353\202\230\353\254\264\354\241\260\352\260\201.py" @@ -0,0 +1,15 @@ +li = list(map(int, input().split())) #31245 +for i in range(5): + for j in range(4): + # 현재 요소(li[j])가 다음 요소(li[j+1])보다 크다면 자리 교환 + if li[j] > li[j + 1]: #3>1 + # 두 요소를 스왑 (교환)하는 과정 + # li[j] 값을 임시 변수 t에 저장 + t = li[j] #t=3 + # li[j]에 li[j+1] 값을 대입 + li[j] = li[j + 1] #1저장(맨앞에) + # li[j+1]에 임시 변수 t 값을 대입 (교환 완료) + li[j + 1] = t #두번째로 3저장(t) + + #결합된 문자열을 출력. + print(" ".join(map(str, li))) \ No newline at end of file diff --git "a/5week/1003-\355\224\274\353\263\264\353\202\230\354\271\230 \355\225\250\354\210\230.py" "b/5week/1003-\355\224\274\353\263\264\353\202\230\354\271\230 \355\225\250\354\210\230.py" new file mode 100644 index 0000000..e69de29 diff --git "a/6week/2606-\353\260\224\354\235\264\353\237\254\354\212\244.py" "b/6week/2606-\353\260\224\354\235\264\353\237\254\354\212\244.py" new file mode 100644 index 0000000..697953f --- /dev/null +++ "b/6week/2606-\353\260\224\354\235\264\353\237\254\354\212\244.py" @@ -0,0 +1,39 @@ +import sys +from collections import deque + +# 입력: 정점(N)과 간선(M)의 개수를 읽음 +N = int(sys.stdin.readline()) # 정점의 개수 +M = int(sys.stdin.readline()) # 간선의 개수 + +# 그래프를 인접 리스트로 표현하기 위해 초기화 +net = [[] for _ in range(N + 1)] # 1번부터 N번까지의 정점 + +# 간선 정보 입력받아 그래프 구성 +for _ in range(M): + a, b = map(int, sys.stdin.readline().split()) + net[a].append(b) # 정점 a에서 b로 가는 간선 추가 + net[b].append(a) # 방향이 없는 그래프이므로 b에서 a로 가는 간선 추가 + +# BFS 함수 정의 +def bfs(): + q = deque() # 큐 생성 + count = 0 # 감염된 컴퓨터 수 + q.append(1) # 1번 컴퓨터를 시작점으로 설정 + visited[1] = True # 1번 컴퓨터를 방문 처리 + + while q: # 큐가 빌 때까지 반복 + cur = q.popleft() # 큐에서 현재 정점(cur)을 꺼냄 + # 현재 정점과 연결된 모든 정점을 탐색 + for val in net[cur]: + if not visited[val]: # 연결된 정점 중 아직 방문하지 않은 정점이 있다면 + q.append(val) # 큐에 추가 + visited[val] = True # 방문 처리 + count += 1 # 감염된 컴퓨터 수 증가 + + print(count) # 모든 감염이 끝난 후 결과 출력 + +# 방문 여부를 저장하는 배열 초기화 +visited = [False for _ in range(N + 1)] # 모든 정점을 방문하지 않은 상태로 초기화 + +# BFS 실행 +bfs() diff --git "a/7week/1780-\354\242\205\354\235\264\354\235\230 \352\260\234\354\210\230.py" "b/7week/1780-\354\242\205\354\235\264\354\235\230 \352\260\234\354\210\230.py" new file mode 100644 index 0000000..cb8321d --- /dev/null +++ "b/7week/1780-\354\242\205\354\235\264\354\235\230 \352\260\234\354\210\230.py" @@ -0,0 +1,41 @@ +import sys + +# 입력 받기 +N = int(sys.stdin.readline()) +paper = [list(map(int, sys.stdin.readline().split())) for _ in range(N)] + +# 개수 저장할 변수 (-1, 0, 1 종이 개수) +count_minus1 = 0 +count_0 = 0 +count_1 = 0 + +# 분할 정복 함수 +def cut(row, col, n): + global count_minus1, count_0, count_1 + first_value = paper[row][col] # 현재 영역의 첫 번째 값 저장 + + # 현재 영역이 모두 같은 숫자인지 확인 + for i in range(row, row + n): + for j in range(col, col + n): + if paper[i][j] != first_value: # 다른 숫자가 하나라도 있다면 9등분 + size = n // 3 # 새로운 크기 (n을 3등분) + for a in range(3): + for b in range(3): + cut(row + a * size, col + b * size, size) # 9개로 나누어 재귀 호출 + return # 9등분 후에는 더 이상 진행하지 않음 + + # 만약 영역이 하나의 숫자로만 이루어졌다면, 해당 숫자의 개수를 증가 + if first_value == -1: + count_minus1 += 1 + elif first_value == 0: + count_0 += 1 + else: + count_1 += 1 + +# 전체 영역(0,0)에서 시작하여 N x N 검사 +cut(0, 0, N) + +# 결과 출력 +print(count_minus1) +print(count_0) +print(count_1) diff --git "a/7week/1992-\354\277\274\353\223\234\355\212\270\353\246\254.py" "b/7week/1992-\354\277\274\353\223\234\355\212\270\353\246\254.py" new file mode 100644 index 0000000..fb03cb0 --- /dev/null +++ "b/7week/1992-\354\277\274\353\223\234\355\212\270\353\246\254.py" @@ -0,0 +1,49 @@ +import sys +sys.setrecursionlimit(10**6) # 재귀 깊이 제한 증가 (최대 10^6번까지 허용) +input = sys.stdin.readline # 빠른 입력을 위한 sys.stdin.readline 사용 + +# 입력 받기 +N = int(input()) # 영상의 크기 N (N은 항상 2^k 형태) +video = [] # 영상 정보를 저장할 리스트 + +# 영상 정보를 2차원 리스트로 저장 +for _ in range(N): + v = [int(x) for x in list(input().rstrip())] # 문자열을 한 글자씩 정수로 변환하여 리스트로 저장 + video.append(v) + +# 쿼드 트리 압축을 수행하는 재귀 함수 +def quadtree(n, vlist): + s = 0 # 현재 영역 내 모든 값의 합을 저장할 변수 + + # 현재 영역의 모든 값의 합을 계산 + for l in vlist: + s += sum(l) # 리스트 내 값들을 모두 더함 + + # 만약 모든 값이 '1'이라면 "1" 반환 (압축 가능) + if s == n**2: + return '1' + + # 만약 모든 값이 '0'이라면 "0" 반환 (압축 가능) + if s == 0: + return '0' + + # 위 조건을 만족하지 않으면 4등분하여 다시 검사 + half = n // 2 # 현재 영역을 4등분할 크기 + + # 결과를 저장할 문자열 (괄호로 감싸기 위해 '(' 추가) + temp = '(' + + temp += quadtree(half, [l[:half] for l in vlist[:half]]) + + temp += quadtree(half, [l[half:] for l in vlist[:half]]) + + temp += quadtree(half, [l[:half] for l in vlist[half:]]) + + temp += quadtree(half, [l[half:] for l in vlist[half:]]) + + temp += ')' + + return temp # 압축된 문자열 반환 + +# 결과 출력 +print(quadtree(N, video)) diff --git "a/7week/2512-\354\230\210\354\202\260.py" "b/7week/2512-\354\230\210\354\202\260.py" new file mode 100644 index 0000000..b8a7810 --- /dev/null +++ "b/7week/2512-\354\230\210\354\202\260.py" @@ -0,0 +1,25 @@ +import sys +input = sys.stdin.readline + +N = int(input()) # 지방 수 +budget = list(map(int, input().split())) # 예산 요청 리스트 +M = int(input()) # 총 예산 + +start, end = 0, max(budget) # 이진 탐색 범위 설정 + +# 예산 요청의 총합이 총 예산 M 이하라면, 최대 요청 금액이 최적해 +if sum(budget) <= M: + print(max(budget)) +else: + while start <= end: + mid = (start + end) // 2 # 중간값(상한액) + + # 상한액 기준으로 배정된 총 예산 계산 + total_budget = sum(min(mid, i) for i in budget) + + if total_budget > M: # 총 예산 초과 시 상한액 줄이기 + end = mid - 1 + else: # 총 예산 이하일 때, 더 높은 상한액을 탐색 + start = mid + 1 + + print(end) # 최적의 상한액 출력 diff --git "a/7week/2630-\354\203\211\354\242\205\354\235\264 \353\247\214\353\223\244\352\270\260.py" "b/7week/2630-\354\203\211\354\242\205\354\235\264 \353\247\214\353\223\244\352\270\260.py" new file mode 100644 index 0000000..ece6b33 --- /dev/null +++ "b/7week/2630-\354\203\211\354\242\205\354\235\264 \353\247\214\353\223\244\352\270\260.py" @@ -0,0 +1,39 @@ +import sys # 표준 입력을 빠르게 받기 위해 sys 모듈 사용 + +# N 입력 받기 (종이의 크기) +N = int(sys.stdin.readline()) + +# N x N 크기의 정사각형 종이 정보 입력 받기 +square = [list(map(int, sys.stdin.readline().split())) for _ in range(N)] + +# 흰색(0)과 파란색(1) 종이의 개수를 저장할 변수 +white = 0 +blue = 0 + +# 종이를 자르는 함수 정의 +def cut(row, column, n): + global white, blue + color = square[row][column] # 현재 영역의 첫 번째 색깔 저장 + + # 현재 영역이 모두 같은 색인지 확인 + for i in range(row, row + n): + for j in range(column, column + n): + if color != square[i][j]: # 하나라도 다른 색이 있으면 나눈다 + cut(row, column, n // 2) # 1사분면 (좌상단) + cut(row, column + n // 2, n // 2) # 2사분면 (우상단) + cut(row + n // 2, column, n // 2) # 3사분면 (좌하단) + cut(row + n // 2, column + n // 2, n // 2) # 4사분면 (우하단) + return # 더 이상 진행하지 않음 + + # 모든 영역이 같은 색이라면, 해당 색깔의 종이 개수를 증가 + if color == 0: + white += 1 # 흰색 종이 개수 증가 + else: + blue += 1 # 파란색 종이 개수 증가 + +# (0,0)에서 시작하여 전체 종이를 검사 +cut(0, 0, N) + +# 결과 출력 +print(white) # 흰색 종이 개수 출력 +print(blue) # 파란색 종이 개수 출력