알고리즘

알고리즘

<백준> 15829번 파이썬 알고리즘

n = int(input()) l = list(map(str, input())) s = 0 for i in range(len(l)): d = int(ord(l[i]) - 96) * (31 ** i) s += d print(s % 1234567891)

알고리즘

<백준> 11866번 파이썬 알고리즘

from collections import deque n, m = map(int, input().split()) s = deque([]) for i in range(1, n+1): s.append(i) print("

알고리즘

<백준> 11651번 파이썬 알고리즘

n = int(input()) s = [] for i in range(n): s.append(list(map(int, input().split()))) s.sort(key = lambda x : (x[1], x[0])) for i in s: print(i[0], i[1]) 11650번에서 lambda x 이부분 순서만 바꾸면 된다

알고리즘

<백준> 11650번 파이썬 알고리즘

n = int(input()) s = [] for i in range(n): s.append(list(map(int, input().split()))) s.sort(key = lambda x : (x[0], x[1])) for i in s: print(i[0], i[1]) []에 리스트를 삽입한다. 그리고 x[0] -> x[1] 순으로 정렬한다

알고리즘

<백준> 11050번 파이썬 알고리즘

def bino_coef(n, k): if k == 0 or n == k: return 1 return bino_coef(n-1, k) + bino_coef(n-1,k-1) n, k = map(int, input().split()) print(bino_coef(n, k)) nCn or nC0 ==> 1임을 이용하여 재귀함수를 만들면 된다

알고리즘

<백준> 10989번 파이썬 알고리즘

import sys n = int(sys.stdin.readline()) b = [0] * 10001 for i in range(n): b[int(sys.stdin.readline())] += 1 for i in range(10001): if b[i] != 0: for j in range(b[i]): print(i)​ 위와 같이 재출했더니 메모리 초과가 났다. sorted를 쓰면 안되는 건가 import sys n = int(sys.stdin.readline()) a = [0] * 10001 for _ in range(n): # m = int(sys.stdin.readline()) a[int(sys.stdin.readline())] += 1 for i in range(10001): if a[i] != 0..

알고리즘

<백준> 10845번 파이썬 알고리즘

import sys n = int(sys.stdin.readline()) q = [] for _ in range(n): m = sys.stdin.readline().split() if m[0] == 'push': q.append(m[1]) elif m[0] == "pop": if len(q) != 0: print(q.pop(0)) else: print(-1) elif m[0] == "size": print(len(q)) elif m[0] == "front": if len(q) != 0: print(q[0]) else: print(-1) elif m[0] == "back": if len(q) != 0: print(q[-1]) else: print(-1) elif m[0] == 'empty': if len(..

알고리즘

<백준> 10866번 파이썬 알고리즘

import sys from collections import deque n = int(sys.stdin.readline()) q = deque() for _ in range(n): m = sys.stdin.readline().split() if m[0] == 'push_front': q.appendleft(m[1]) elif m[0] == 'push_back': q.append(m[1]) elif m[0] == "pop_front": if len(q) != 0: print(q.popleft()) else: print(-1) elif m[0] == "pop_back": if len(q) != 0: print(q.pop()) else: print(-1) elif m[0] == "size": print(le..

알고리즘

<백준> 10828번 파이썬 알고리즘

import sys n = int(sys.stdin.readline()) stk = [] for _ in range(n): m = sys.stdin.readline().split() if m[0] == 'push': stk.append(m[1]) elif m[0] == "pop": if len(stk) != 0: print(stk.pop()) else: print(-1) elif m[0] == "size": print(len(stk)) elif m[0] == "top": if len(stk) != 0: print(stk[-1]) else: print(-1) elif m[0] == 'empty': if len(stk) != 0: print(0) else: print(1)

알고리즘

<백준> 10816번 파이썬 알고리즘

n = int(input()) l = list(map(int, input().split())) m = int(input()) k = list(map(int, input().split())) r = [] for i in k: r.append(l.count(i)) for j in r: print(j, end= " ") 시간 초과 났다 실버4 문제치고 너무 쉽다는 생각이 들긴했다 n = int(input()) l = list(map(int, input().split())) m = int(input()) k = list(map(int, input().split())) n_count = {} for i in l: try: n_count[i] += 1 except: n_count[i] = 1 res = [] for..

changha.
'알고리즘' 카테고리의 글 목록 (9 Page)