From 86c00231c0c68de461d191e599404192c77e2025 Mon Sep 17 00:00:00 2001 From: Zerohertz Date: Sat, 8 Jul 2023 22:40:16 +0900 Subject: [PATCH] :art: Style: Format --- .github/workflows/Formatter.yml | 2 +- .gitignore | 2 +- .../13705 (Incompleted)/Legacy/ver1.py | 2 +- BOJ/Gold/10026/main.py | 8 +-- BOJ/Gold/1011/main.py | 4 +- BOJ/Gold/1013/main.py | 2 +- BOJ/Gold/1041/main.py | 14 ++++- BOJ/Gold/1053/main.py | 20 ++---- BOJ/Gold/1062/Legacy/ver1.py | 2 +- BOJ/Gold/1062/main.py | 12 ++-- BOJ/Gold/10868/main.py | 2 +- BOJ/Gold/11049/main.py | 5 +- BOJ/Gold/11404/main.py | 4 +- BOJ/Gold/1174/main.py | 2 +- BOJ/Gold/12100/main.py | 12 ++-- BOJ/Gold/1275/main.py | 10 +-- BOJ/Gold/12851/main.py | 3 +- BOJ/Gold/12865/Legacy/ver1.py | 6 +- BOJ/Gold/12869/main.py | 6 +- BOJ/Gold/1339/Legacy/ver1.py | 2 +- BOJ/Gold/1339/main.py | 2 +- BOJ/Gold/13459/main.py | 62 ++++++++++--------- BOJ/Gold/13460/main.py | 62 ++++++++++--------- BOJ/Gold/13913/main.py | 2 +- BOJ/Gold/14786/main.py | 2 +- BOJ/Gold/14891/Legacy/ver1.py | 8 +-- BOJ/Gold/14891/main.py | 2 +- BOJ/Gold/1600/main.py | 14 ++++- BOJ/Gold/1707/main.py | 4 +- BOJ/Gold/1717/main.py | 4 +- BOJ/Gold/17214/Legacy/ver1.py | 14 ++--- BOJ/Gold/17214/main.py | 32 +++++----- BOJ/Gold/17387/main.py | 4 +- BOJ/Gold/1753/Legacy/ver1.py | 2 +- BOJ/Gold/1753/main.py | 2 +- BOJ/Gold/1759/main.py | 4 +- BOJ/Gold/1823/main.py | 19 +----- BOJ/Gold/20058/main.py | 4 +- BOJ/Gold/2042/main.py | 10 +-- BOJ/Gold/2174/main.py | 17 ++--- BOJ/Gold/2239/main.py | 2 +- BOJ/Gold/2251/main.py | 2 +- BOJ/Gold/2447/main.py | 6 +- BOJ/Gold/3055/main.py | 18 +++--- BOJ/Gold/3109/Legacy/ver1.py | 8 +-- BOJ/Gold/3109/main.py | 5 +- BOJ/Gold/3190/main.py | 7 +-- BOJ/Gold/5430/main.py | 10 +-- BOJ/Gold/7569/main.py | 11 +++- BOJ/Gold/7662/Legacy/ver1.py | 6 +- BOJ/Gold/7662/main.py | 6 +- BOJ/Gold/9328/main.py | 34 +++++----- BOJ/Gold/9466/main.py | 4 +- BOJ/Gold/9553/Legacy/ver1.py | 18 +++--- BOJ/Gold/9553/Legacy/ver2.py | 4 +- BOJ/Gold/9553/main.py | 20 ++++-- BOJ/Platinum/1067/main.py | 10 +-- .../1510 (Incompleted)/Legacy/ver1.py | 13 ++-- BOJ/Platinum/15807/main.py | 3 +- BOJ/Platinum/9206/main.py | 4 +- BOJ/Silver/1010/main.py | 5 +- BOJ/Silver/1018/main.py | 8 +-- BOJ/Silver/1058/main.py | 2 +- BOJ/Silver/1074/Legacy/ver1.py | 4 +- BOJ/Silver/1080/main.py | 6 +- BOJ/Silver/10816/main.py | 4 +- BOJ/Silver/10828/Legacy/ver1.py | 10 +-- BOJ/Silver/10828/main.py | 10 +-- BOJ/Silver/10845/main.py | 12 ++-- BOJ/Silver/10866/main.py | 16 ++--- BOJ/Silver/11399/main.py | 2 +- BOJ/Silver/11660/main.py | 3 +- BOJ/Silver/11723/main.py | 12 ++-- BOJ/Silver/11866/Legacy/ver1.py | 8 +-- BOJ/Silver/11866/main.py | 6 +- BOJ/Silver/1193/main.py | 4 +- BOJ/Silver/1213/main.py | 4 +- BOJ/Silver/12208/main.py | 22 ++++--- BOJ/Silver/12209/main.py | 22 ++++--- BOJ/Silver/1260/main.py | 4 +- BOJ/Silver/12852/main.py | 2 +- BOJ/Silver/1402/main.py | 2 +- BOJ/Silver/1436/main.py | 2 +- BOJ/Silver/14600/main.py | 8 +-- BOJ/Silver/1543/main.py | 2 +- BOJ/Silver/15650/main.py | 2 +- BOJ/Silver/15654/main.py | 2 +- BOJ/Silver/1654/main.py | 2 +- BOJ/Silver/1676/main.py | 2 +- BOJ/Silver/17478/main.py | 16 ++--- BOJ/Silver/18258/main.py | 12 ++-- BOJ/Silver/1874/main.py | 6 +- BOJ/Silver/18870/main.py | 4 +- BOJ/Silver/1929/main.py | 2 +- BOJ/Silver/1978/Legacy/ver1.py | 2 +- BOJ/Silver/1991/main.py | 18 +++--- BOJ/Silver/2164/main.py | 4 +- BOJ/Silver/25178/main.py | 12 ++-- BOJ/Silver/2583/main.py | 4 +- BOJ/Silver/4949/main.py | 18 +++--- BOJ/Silver/7568/main.py | 2 +- BOJ/Silver/9012/main.py | 8 +-- BOJ/Silver/9655/main.py | 4 +- CodeUp/6095/main.py | 2 +- CodeUp/6096/main.py | 14 ++--- CodeUp/6097/main.py | 10 +-- CodeUp/6098/main.py | 10 +-- .../2015_Contest/LongestPassword/README.md | 2 +- .../2015_Contest/LongestPassword/main.py | 1 + .../Algorithmic_skills/FirstUnique/README.md | 2 +- .../StrSymmetryPoint/README.md | 2 +- .../StrSymmetryPoint/main.py | 1 + .../Algorithmic_skills/TreeHeight/README.md | 2 +- Functions/SegmentTree.py | 10 +-- Functions/fft.py | 10 +-- Functions/returnPN.py | 2 +- .../main.py" | 26 +++++--- .../main.py" | 2 +- .../main.py" | 4 +- .../main.py" | 4 +- .../Legacy/ver1_DFS.py" | 8 ++- .../main.py" | 8 ++- .../main.py" | 1 + .../main.py" | 4 +- .../main.py" | 2 +- .../main.py" | 2 +- .../main.py" | 2 +- .../main.py" | 8 +-- Programmers/Sort/H-Index/main.py | 1 - .../main.py" | 2 +- .../main.py" | 3 +- .../main.py" | 4 +- .../Legacy/ver1.py" | 8 +-- .../main.py" | 8 +-- .../main.py" | 4 +- .../main.py" | 2 +- README.md | 2 +- 137 files changed, 558 insertions(+), 496 deletions(-) diff --git a/.github/workflows/Formatter.yml b/.github/workflows/Formatter.yml index 74177a6..3e13fa5 100644 --- a/.github/workflows/Formatter.yml +++ b/.github/workflows/Formatter.yml @@ -41,4 +41,4 @@ jobs: git push else echo "No code changes." - fi \ No newline at end of file + fi diff --git a/.gitignore b/.gitignore index 60cfa5f..14c2239 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ **/*.pdf *.ini .DS_Store -Study \ No newline at end of file +Study diff --git a/BOJ/Diamond/13705 (Incompleted)/Legacy/ver1.py b/BOJ/Diamond/13705 (Incompleted)/Legacy/ver1.py index 4d2599a..98c44d5 100644 --- a/BOJ/Diamond/13705 (Incompleted)/Legacy/ver1.py +++ b/BOJ/Diamond/13705 (Incompleted)/Legacy/ver1.py @@ -7,7 +7,7 @@ def f(A, B, C, x): def fp(A, B, x): - return - A - B * math.cos(x) + return -A - B * math.cos(x) def newrap(A, B, C, x): diff --git a/BOJ/Gold/10026/main.py b/BOJ/Gold/10026/main.py index 5a3ecf3..5a1bf47 100644 --- a/BOJ/Gold/10026/main.py +++ b/BOJ/Gold/10026/main.py @@ -4,13 +4,13 @@ read = sys.stdin.readline N = int(read()) -l = [['' for _ in range(N)] for _ in range(N)] -juklock = [['' for _ in range(N)] for _ in range(N)] +l = [["" for _ in range(N)] for _ in range(N)] +juklock = [["" for _ in range(N)] for _ in range(N)] for i in range(N): l[i] = list(read().rstrip()) for j in range(N): - if l[i][j] == 'G': - juklock[i][j] = 'R' + if l[i][j] == "G": + juklock[i][j] = "R" else: juklock[i][j] = l[i][j] diff --git a/BOJ/Gold/1011/main.py b/BOJ/Gold/1011/main.py index dd8031d..ba24a49 100644 --- a/BOJ/Gold/1011/main.py +++ b/BOJ/Gold/1011/main.py @@ -7,8 +7,8 @@ for _ in range(T): a, b = map(int, read().split()) tmp = b - a - max = int(tmp ** 0.5) - tmp -= max ** 2 + max = int(tmp**0.5) + tmp -= max**2 cnt = 2 * max - 1 if tmp % max == 0: cnt += tmp // max diff --git a/BOJ/Gold/1013/main.py b/BOJ/Gold/1013/main.py index 8c07f07..7a57147 100644 --- a/BOJ/Gold/1013/main.py +++ b/BOJ/Gold/1013/main.py @@ -6,7 +6,7 @@ T = int(read()) for _ in range(T): S = read().strip() - p = re.compile('(100+1+|01)+') + p = re.compile("(100+1+|01)+") res = p.fullmatch(S) if res: print("YES") diff --git a/BOJ/Gold/1041/main.py b/BOJ/Gold/1041/main.py index 1c5fd03..d9a5792 100644 --- a/BOJ/Gold/1041/main.py +++ b/BOJ/Gold/1041/main.py @@ -19,8 +19,16 @@ for i in tmp: d2 = min(d2, l[i[0]] + l[i[1]]) - tmp = ((0, 1, 2), (0, 1, 3), (0, 2, 4), (0, 3, 4), - (5, 1, 2), (5, 1, 3), (5, 2, 4), (5, 3, 4)) + tmp = ( + (0, 1, 2), + (0, 1, 3), + (0, 2, 4), + (0, 3, 4), + (5, 1, 2), + (5, 1, 3), + (5, 2, 4), + (5, 3, 4), + ) d3 = sys.maxsize for i in tmp: @@ -28,6 +36,6 @@ d2n = (N - 1) * 4 + (N - 2) * 4 d3n = 4 - d1n = N ** 3 - ((N - 1) * (N - 2) * (N - 2)) - d2n - d3n + d1n = N**3 - ((N - 1) * (N - 2) * (N - 2)) - d2n - d3n print(d1 * d1n + d2 * d2n + d3 * d3n) diff --git a/BOJ/Gold/1053/main.py b/BOJ/Gold/1053/main.py index c223860..d213dab 100644 --- a/BOJ/Gold/1053/main.py +++ b/BOJ/Gold/1053/main.py @@ -6,8 +6,8 @@ def swap(s, idx1, idx2): tmp = s[idx2] - s = s[:idx2] + s[idx1] + s[idx2 + 1:] - s = s[:idx1] + tmp + s[idx1 + 1:] + s = s[:idx2] + s[idx1] + s[idx2 + 1 :] + s = s[:idx1] + tmp + s[idx1 + 1 :] return s @@ -23,18 +23,10 @@ def Palindrome(s, idx1, idx2): if idx1 >= idx2: return 0 res = min( - Palindrome( - s, - idx1 + 1, - idx2) + 1, - Palindrome( - s, - idx1, - idx2 - 1) + 1, - Palindrome( - s, - idx1 + 1, - idx2 - 1) + 1) + Palindrome(s, idx1 + 1, idx2) + 1, + Palindrome(s, idx1, idx2 - 1) + 1, + Palindrome(s, idx1 + 1, idx2 - 1) + 1, + ) cache[idx1][idx2] = res return res diff --git a/BOJ/Gold/1062/Legacy/ver1.py b/BOJ/Gold/1062/Legacy/ver1.py index d889188..28e1522 100644 --- a/BOJ/Gold/1062/Legacy/ver1.py +++ b/BOJ/Gold/1062/Legacy/ver1.py @@ -7,7 +7,7 @@ s = set() wordset = [] -antic = set('antic') +antic = set("antic") tupleantic = tuple(antic) for i in range(N): diff --git a/BOJ/Gold/1062/main.py b/BOJ/Gold/1062/main.py index 06a2a6e..9ed5d55 100644 --- a/BOJ/Gold/1062/main.py +++ b/BOJ/Gold/1062/main.py @@ -7,14 +7,14 @@ s = set() wordset = [] -antic = set('antic') +antic = set("antic") for i in range(N): word = read().rstrip() tmpwordset = set(word) wordset.append(tmpwordset) -s = set(chr(i) for i in range(ord('a'), ord('z') + 1)) - antic +s = set(chr(i) for i in range(ord("a"), ord("z") + 1)) - antic if K < 5: print(0) @@ -24,20 +24,20 @@ res = 0 l = [False for _ in range(26)] for ch in antic: - l[ord(ch) - ord('a')] = True + l[ord(ch) - ord("a")] = True for teach in combinations(s, K - 5): tmp = 0 for t in teach: - l[ord(t) - ord('a')] = True + l[ord(t) - ord("a")] = True for word in wordset: status = True for w in word: - if not l[ord(w) - ord('a')]: + if not l[ord(w) - ord("a")]: status = False break if status: tmp += 1 for t in teach: - l[ord(t) - ord('a')] = False + l[ord(t) - ord("a")] = False res = max(res, tmp) print(res) diff --git a/BOJ/Gold/10868/main.py b/BOJ/Gold/10868/main.py index 7d9511d..6320626 100644 --- a/BOJ/Gold/10868/main.py +++ b/BOJ/Gold/10868/main.py @@ -1,6 +1,6 @@ import sys -sys.setrecursionlimit(10 ** 9) +sys.setrecursionlimit(10**9) read = sys.stdin.readline diff --git a/BOJ/Gold/11049/main.py b/BOJ/Gold/11049/main.py index 7c67a79..3f11dfa 100644 --- a/BOJ/Gold/11049/main.py +++ b/BOJ/Gold/11049/main.py @@ -12,7 +12,8 @@ x = i + j dp[j][x] = sys.maxsize for k in range(j, x): - dp[j][x] = min(dp[j][x], dp[j][k] + dp[k + 1] - [x] + l[j][0] * l[k][1] * l[x][1]) + dp[j][x] = min( + dp[j][x], dp[j][k] + dp[k + 1][x] + l[j][0] * l[k][1] * l[x][1] + ) print(dp[0][N - 1]) diff --git a/BOJ/Gold/11404/main.py b/BOJ/Gold/11404/main.py index b62c264..5bcf81f 100644 --- a/BOJ/Gold/11404/main.py +++ b/BOJ/Gold/11404/main.py @@ -21,7 +21,7 @@ for i in res: for j in i: if j == INF: - print(0, end=' ') + print(0, end=" ") else: - print(j, end=' ') + print(j, end=" ") print() diff --git a/BOJ/Gold/1174/main.py b/BOJ/Gold/1174/main.py index a20ad20..afa6d08 100644 --- a/BOJ/Gold/1174/main.py +++ b/BOJ/Gold/1174/main.py @@ -8,7 +8,7 @@ for i in range(1, 10): for j in combinations(l, i): - res.append(int(''.join(j[::-1]))) + res.append(int("".join(j[::-1]))) res.sort() res.append(9876543210) diff --git a/BOJ/Gold/12100/main.py b/BOJ/Gold/12100/main.py index 94faa79..849b38c 100644 --- a/BOJ/Gold/12100/main.py +++ b/BOJ/Gold/12100/main.py @@ -13,12 +13,16 @@ def n2n(i, j, dir): while True: - if not (((0 <= i < N) and (0 <= j < N)) and ( - (0 <= i + dir[1] < N) and (0 <= j + dir[0] < N))): + if not ( + ((0 <= i < N) and (0 <= j < N)) + and ((0 <= i + dir[1] < N) and (0 <= j + dir[0] < N)) + ): break elif not G[i][j] == 0: - if G[i + dir[1]][j + dir[0] - ] == G[i][j] and not visited[i + dir[1]][j + dir[0]]: + if ( + G[i + dir[1]][j + dir[0]] == G[i][j] + and not visited[i + dir[1]][j + dir[0]] + ): G[i + dir[1]][j + dir[0]] = G[i][j] * 2 G[i][j] = 0 visited[i + dir[1]][j + dir[0]] = True diff --git a/BOJ/Gold/1275/main.py b/BOJ/Gold/1275/main.py index 82ca369..6623892 100644 --- a/BOJ/Gold/1275/main.py +++ b/BOJ/Gold/1275/main.py @@ -8,8 +8,9 @@ def init(node, start, end): tree[node] = l[start] return tree[node] else: - tree[node] = init(node * 2, start, (start + end) // 2) + \ - init(node * 2 + 1, (start + end) // 2 + 1, end) + tree[node] = init(node * 2, start, (start + end) // 2) + init( + node * 2 + 1, (start + end) // 2 + 1, end + ) return tree[node] @@ -27,8 +28,9 @@ def segSum(node, start, end, left, right): return 0 if left <= start and end <= right: return tree[node] - return segSum(node * 2, start, (start + end) // 2, left, right) + \ - segSum(node * 2 + 1, (start + end) // 2 + 1, end, left, right) + return segSum(node * 2, start, (start + end) // 2, left, right) + segSum( + node * 2 + 1, (start + end) // 2 + 1, end, left, right + ) N, Q = map(int, read().split()) diff --git a/BOJ/Gold/12851/main.py b/BOJ/Gold/12851/main.py index cc552dc..e03f273 100644 --- a/BOJ/Gold/12851/main.py +++ b/BOJ/Gold/12851/main.py @@ -13,8 +13,7 @@ def BFS(pos): while q: tmp, t = q.popleft() for i in [tmp - 1, tmp + 1, tmp * 2]: - if 0 <= i <= 100_000 and ( - visit[i][0] == -1 or visit[i][0] == t + 1): + if 0 <= i <= 100_000 and (visit[i][0] == -1 or visit[i][0] == t + 1): if visit[i][0] == t + 1: visit[i][1] += visit[tmp][1] else: diff --git a/BOJ/Gold/12865/Legacy/ver1.py b/BOJ/Gold/12865/Legacy/ver1.py index 3e2781d..8da28f1 100644 --- a/BOJ/Gold/12865/Legacy/ver1.py +++ b/BOJ/Gold/12865/Legacy/ver1.py @@ -13,12 +13,12 @@ tmpbin = bin(i) tmpb = tmpbin[2:] binidx = [tmpb[j] for j in range(len(tmpb))] - idx = ['0' for j in range(N)] - idx[N - len(binidx):] = binidx + idx = ["0" for j in range(N)] + idx[N - len(binidx) :] = binidx totW = 0 totV = 0 for j in range(N): - if idx[j] == '1': + if idx[j] == "1": totW = totW + W[j] totV = totV + V[j] if totW <= K: diff --git a/BOJ/Gold/12869/main.py b/BOJ/Gold/12869/main.py index a77a009..692fbb3 100644 --- a/BOJ/Gold/12869/main.py +++ b/BOJ/Gold/12869/main.py @@ -22,7 +22,9 @@ def solution(x, y, z, cnt): while len(SCV) < 3: SCV += [0] ans = 100 -dp = [[[100] * (max(SCV) + 1) for i in range((max(SCV) + 1))] - for j in range((max(SCV) + 1))] +dp = [ + [[100] * (max(SCV) + 1) for i in range((max(SCV) + 1))] + for j in range((max(SCV) + 1)) +] solution(SCV[0], SCV[1], SCV[2], 0) print(ans) diff --git a/BOJ/Gold/1339/Legacy/ver1.py b/BOJ/Gold/1339/Legacy/ver1.py index 42614f6..c588afe 100644 --- a/BOJ/Gold/1339/Legacy/ver1.py +++ b/BOJ/Gold/1339/Legacy/ver1.py @@ -28,6 +28,6 @@ res = 0 for i, j in enumerate(l): for k in j: - res += 10 ** i * d[k] + res += 10**i * d[k] print(res) diff --git a/BOJ/Gold/1339/main.py b/BOJ/Gold/1339/main.py index d379f49..db86bc5 100644 --- a/BOJ/Gold/1339/main.py +++ b/BOJ/Gold/1339/main.py @@ -8,7 +8,7 @@ for i in range(N): tmp = read().rstrip() for j, k in enumerate(tmp[::-1]): - l[ord(k) - ord('A')] += 10 ** j + l[ord(k) - ord("A")] += 10**j l.sort(reverse=True) diff --git a/BOJ/Gold/13459/main.py b/BOJ/Gold/13459/main.py index 252eaba..f9ffb63 100644 --- a/BOJ/Gold/13459/main.py +++ b/BOJ/Gold/13459/main.py @@ -6,47 +6,48 @@ N, M = map(int, read().split()) l = [[0 for _ in range(M)] for _ in range(N)] -pos = {'R': [], 'B': []} +pos = {"R": [], "B": []} for i in range(N): l[i] = list(read().rstrip()) for j in range(M): - if l[i][j] == 'R': - pos['R'] = [i, j] - l[i][j] = '.' - elif l[i][j] == 'B': - pos['B'] = [i, j] - l[i][j] = '.' + if l[i][j] == "R": + pos["R"] = [i, j] + l[i][j] = "." + elif l[i][j] == "B": + pos["B"] = [i, j] + l[i][j] = "." dirdict = {0: (1, 0), 1: (0, 1), 2: (-1, 0), 3: (0, -1)} def gravity(tmppos, direction): status = 0 - rx, ry = tmppos['R'] - bx, by = tmppos['B'] + rx, ry = tmppos["R"] + bx, by = tmppos["B"] v1, v2 = dirdict[direction] RedGoalIn = False while True: - if l[rx + v1][ry + v2] != '#' or l[bx + - v1][by + v2] != '#': # 둘 중 하나가 이동 가능할 때 - if l[rx + v1][ry + v2] != '#' and not RedGoalIn: # Red 이동 + if l[rx + v1][ry + v2] != "#" or l[bx + v1][by + v2] != "#": # 둘 중 하나가 이동 가능할 때 + if l[rx + v1][ry + v2] != "#" and not RedGoalIn: # Red 이동 rx += v1 ry += v2 majimak = True - if l[bx + v1][by + v2] != '#': # Blue 이동 + if l[bx + v1][by + v2] != "#": # Blue 이동 bx += v1 by += v2 majimak = False - if l[rx][ry] == 'O': + if l[rx][ry] == "O": RedGoalIn = True - if l[bx][by] == 'O': + if l[bx][by] == "O": status = -100 return tmppos, status - if l[rx + v1][ry + v2] == '#' and l[bx + - v1][by + v2] == '#': # 둘 다 이동 불가 시 이동 정지 + if ( + l[rx + v1][ry + v2] == "#" and l[bx + v1][by + v2] == "#" + ): # 둘 다 이동 불가 시 이동 정지 break - if RedGoalIn and l[bx + v1][by + - v2] == '#': # Red가 구멍으로 들어가고 Blue는 이동 불가 시 이동 정지 + if ( + RedGoalIn and l[bx + v1][by + v2] == "#" + ): # Red가 구멍으로 들어가고 Blue는 이동 불가 시 이동 정지 break if rx == bx and ry == by: # Red와 Blue 충돌 시 if majimak: @@ -57,22 +58,23 @@ def gravity(tmppos, direction): by -= v2 if RedGoalIn: status = 100 - tmppos['R'] = [rx, ry] - tmppos['B'] = [bx, by] + tmppos["R"] = [rx, ry] + tmppos["B"] = [bx, by] return tmppos, status -visit = [[[[False for _ in range(M)] for _ in range(N)] - for _ in range(M)] for _ in range(N)] +visit = [ + [[[False for _ in range(M)] for _ in range(N)] for _ in range(M)] for _ in range(N) +] -q = deque([[pos['R'], pos['B'], 0]]) -visit[pos['R'][0]][pos['R'][1]][pos['B'][0]][pos['B'][1]] = True +q = deque([[pos["R"], pos["B"], 0]]) +visit[pos["R"][0]][pos["R"][1]][pos["B"][0]][pos["B"][1]] = True while q: RedPos, BluePos, cnt = q.popleft() for i in range(4): - pos['R'] = RedPos - pos['B'] = BluePos + pos["R"] = RedPos + pos["B"] = BluePos a, b = gravity(pos, i) if b == 100: if cnt + 1 > 10: @@ -82,7 +84,7 @@ def gravity(tmppos, direction): print(1) exit() else: - if not visit[a['R'][0]][a['R'][1]][a['B'][0]][a['B'][1]]: - visit[a['R'][0]][a['R'][1]][a['B'][0]][a['B'][1]] = True - q.append([a['R'], a['B'], cnt + 1]) + if not visit[a["R"][0]][a["R"][1]][a["B"][0]][a["B"][1]]: + visit[a["R"][0]][a["R"][1]][a["B"][0]][a["B"][1]] = True + q.append([a["R"], a["B"], cnt + 1]) print(0) diff --git a/BOJ/Gold/13460/main.py b/BOJ/Gold/13460/main.py index 162412a..50724a4 100644 --- a/BOJ/Gold/13460/main.py +++ b/BOJ/Gold/13460/main.py @@ -6,47 +6,48 @@ N, M = map(int, read().split()) l = [[0 for _ in range(M)] for _ in range(N)] -pos = {'R': [], 'B': []} +pos = {"R": [], "B": []} for i in range(N): l[i] = list(read().rstrip()) for j in range(M): - if l[i][j] == 'R': - pos['R'] = [i, j] - l[i][j] = '.' - elif l[i][j] == 'B': - pos['B'] = [i, j] - l[i][j] = '.' + if l[i][j] == "R": + pos["R"] = [i, j] + l[i][j] = "." + elif l[i][j] == "B": + pos["B"] = [i, j] + l[i][j] = "." dirdict = {0: (1, 0), 1: (0, 1), 2: (-1, 0), 3: (0, -1)} def gravity(tmppos, direction): status = 0 - rx, ry = tmppos['R'] - bx, by = tmppos['B'] + rx, ry = tmppos["R"] + bx, by = tmppos["B"] v1, v2 = dirdict[direction] RedGoalIn = False while True: - if l[rx + v1][ry + v2] != '#' or l[bx + - v1][by + v2] != '#': # 둘 중 하나가 이동 가능할 때 - if l[rx + v1][ry + v2] != '#' and not RedGoalIn: # Red 이동 + if l[rx + v1][ry + v2] != "#" or l[bx + v1][by + v2] != "#": # 둘 중 하나가 이동 가능할 때 + if l[rx + v1][ry + v2] != "#" and not RedGoalIn: # Red 이동 rx += v1 ry += v2 majimak = True - if l[bx + v1][by + v2] != '#': # Blue 이동 + if l[bx + v1][by + v2] != "#": # Blue 이동 bx += v1 by += v2 majimak = False - if l[rx][ry] == 'O': + if l[rx][ry] == "O": RedGoalIn = True - if l[bx][by] == 'O': + if l[bx][by] == "O": status = -100 return tmppos, status - if l[rx + v1][ry + v2] == '#' and l[bx + - v1][by + v2] == '#': # 둘 다 이동 불가 시 이동 정지 + if ( + l[rx + v1][ry + v2] == "#" and l[bx + v1][by + v2] == "#" + ): # 둘 다 이동 불가 시 이동 정지 break - if RedGoalIn and l[bx + v1][by + - v2] == '#': # Red가 구멍으로 들어가고 Blue는 이동 불가 시 이동 정지 + if ( + RedGoalIn and l[bx + v1][by + v2] == "#" + ): # Red가 구멍으로 들어가고 Blue는 이동 불가 시 이동 정지 break if rx == bx and ry == by: # Red와 Blue 충돌 시 if majimak: @@ -57,22 +58,23 @@ def gravity(tmppos, direction): by -= v2 if RedGoalIn: status = 100 - tmppos['R'] = [rx, ry] - tmppos['B'] = [bx, by] + tmppos["R"] = [rx, ry] + tmppos["B"] = [bx, by] return tmppos, status -visit = [[[[False for _ in range(M)] for _ in range(N)] - for _ in range(M)] for _ in range(N)] +visit = [ + [[[False for _ in range(M)] for _ in range(N)] for _ in range(M)] for _ in range(N) +] -q = deque([[pos['R'], pos['B'], 0]]) -visit[pos['R'][0]][pos['R'][1]][pos['B'][0]][pos['B'][1]] = True +q = deque([[pos["R"], pos["B"], 0]]) +visit[pos["R"][0]][pos["R"][1]][pos["B"][0]][pos["B"][1]] = True while q: RedPos, BluePos, cnt = q.popleft() for i in range(4): - pos['R'] = RedPos - pos['B'] = BluePos + pos["R"] = RedPos + pos["B"] = BluePos a, b = gravity(pos, i) if b == 100: if cnt + 1 > 10: @@ -82,7 +84,7 @@ def gravity(tmppos, direction): print(cnt + 1) exit() else: - if not visit[a['R'][0]][a['R'][1]][a['B'][0]][a['B'][1]]: - visit[a['R'][0]][a['R'][1]][a['B'][0]][a['B'][1]] = True - q.append([a['R'], a['B'], cnt + 1]) + if not visit[a["R"][0]][a["R"][1]][a["B"][0]][a["B"][1]]: + visit[a["R"][0]][a["R"][1]][a["B"][0]][a["B"][1]] = True + q.append([a["R"], a["B"], cnt + 1]) print(-1) diff --git a/BOJ/Gold/13913/main.py b/BOJ/Gold/13913/main.py index c9b5807..8b7fa69 100644 --- a/BOJ/Gold/13913/main.py +++ b/BOJ/Gold/13913/main.py @@ -29,4 +29,4 @@ def BFS(N, K): res.append(tmp) tmp = c[tmp] for i in res[::-1]: - print(i, end=' ') + print(i, end=" ") diff --git a/BOJ/Gold/14786/main.py b/BOJ/Gold/14786/main.py index 8026b56..65fa3cb 100644 --- a/BOJ/Gold/14786/main.py +++ b/BOJ/Gold/14786/main.py @@ -7,7 +7,7 @@ def f(A, B, C, x): def fp(A, B, x): - return - A - B * math.cos(x) + return -A - B * math.cos(x) def newrap(A, B, C, x): diff --git a/BOJ/Gold/14891/Legacy/ver1.py b/BOJ/Gold/14891/Legacy/ver1.py index 19a3db2..9dc250a 100644 --- a/BOJ/Gold/14891/Legacy/ver1.py +++ b/BOJ/Gold/14891/Legacy/ver1.py @@ -32,13 +32,13 @@ def dupL(L): def returnScore(T1, T2, T3, T4): sc = 0 - if T1[0] == '1': + if T1[0] == "1": sc += 1 - if T2[0] == '1': + if T2[0] == "1": sc += 2 - if T3[0] == '1': + if T3[0] == "1": sc += 4 - if T4[0] == '1': + if T4[0] == "1": sc += 8 return sc diff --git a/BOJ/Gold/14891/main.py b/BOJ/Gold/14891/main.py index 83c534c..c474514 100644 --- a/BOJ/Gold/14891/main.py +++ b/BOJ/Gold/14891/main.py @@ -29,6 +29,6 @@ def rotate_left(x, d): ans = 0 for i in range(4): - ans += gears[i + 1][0] * (2 ** i) + ans += gears[i + 1][0] * (2**i) print(ans) diff --git a/BOJ/Gold/1600/main.py b/BOJ/Gold/1600/main.py index 1ce3b1c..c87feb3 100644 --- a/BOJ/Gold/1600/main.py +++ b/BOJ/Gold/1600/main.py @@ -27,13 +27,23 @@ def BFS(): return visited[x][y][tmpK] for i in range(4): nx, ny = x + m1[i], y + m2[i] - if 0 <= nx < H and 0 <= ny < W and not G[nx][ny] == 1 and visited[nx][ny][tmpK] == 0: + if ( + 0 <= nx < H + and 0 <= ny < W + and not G[nx][ny] == 1 + and visited[nx][ny][tmpK] == 0 + ): visited[nx][ny][tmpK] = visited[x][y][tmpK] + 1 q.append((nx, ny, tmpK)) if tmpK > 0: for i in range(8): nx, ny = x + h1[i], y + h2[i] - if 0 <= nx < H and 0 <= ny < W and not G[nx][ny] == 1 and visited[nx][ny][tmpK - 1] == 0: + if ( + 0 <= nx < H + and 0 <= ny < W + and not G[nx][ny] == 1 + and visited[nx][ny][tmpK - 1] == 0 + ): visited[nx][ny][tmpK - 1] = visited[x][y][tmpK] + 1 q.append((nx, ny, tmpK - 1)) return -1 diff --git a/BOJ/Gold/1707/main.py b/BOJ/Gold/1707/main.py index e4c3160..cf5dd1f 100644 --- a/BOJ/Gold/1707/main.py +++ b/BOJ/Gold/1707/main.py @@ -32,6 +32,6 @@ def DFS(pos, c): if not res: break if res: - print('YES') + print("YES") else: - print('NO') + print("NO") diff --git a/BOJ/Gold/1717/main.py b/BOJ/Gold/1717/main.py index 0031d82..e876ad7 100644 --- a/BOJ/Gold/1717/main.py +++ b/BOJ/Gold/1717/main.py @@ -26,6 +26,6 @@ def union(b, c): union(b, c) else: if find_par(b) == find_par(c): - print('YES') + print("YES") else: - print('NO') + print("NO") diff --git a/BOJ/Gold/17214/Legacy/ver1.py b/BOJ/Gold/17214/Legacy/ver1.py index a46f200..0e4f8b3 100644 --- a/BOJ/Gold/17214/Legacy/ver1.py +++ b/BOJ/Gold/17214/Legacy/ver1.py @@ -1,15 +1,15 @@ -st = input().split('+') -res = '' +st = input().split("+") +res = "" for i in range(len(st)): - if st[i][-1] == 'x': + if st[i][-1] == "x": tmp = int(st[i][:-1]) / 2 - res = str(int(tmp)) + 'xx' + res = str(int(tmp)) + "xx" else: if len(res): - res += '+' + str(int(st[i][:])) + 'x' + res += "+" + str(int(st[i][:])) + "x" else: - res += str(int(st[i][:])) + 'x' -res += '+W' + res += str(int(st[i][:])) + "x" +res += "+W" print(res) diff --git a/BOJ/Gold/17214/main.py b/BOJ/Gold/17214/main.py index 4a9283d..b6a7362 100644 --- a/BOJ/Gold/17214/main.py +++ b/BOJ/Gold/17214/main.py @@ -1,7 +1,7 @@ st = input() -tmp = '' +tmp = "" status = False -res = '' +res = "" try: iszero = int(st) @@ -9,41 +9,41 @@ iszero = 1 for i in range(len(st)): - if 'x' in st: - if st[i] == 'x': + if "x" in st: + if st[i] == "x": if int(tmp) // 2 == 1: - res = 'xx' + res = "xx" elif int(tmp) // 2 == -1: - res = '-xx' + res = "-xx" else: - res = str(int(tmp) // 2) + 'xx' - tmp = '' + res = str(int(tmp) // 2) + "xx" + tmp = "" status = True else: if status: tmp += st[i] if i + 1 == len(st): if int(tmp) == 1: - res += '+x' + res += "+x" elif int(tmp) == -1: - res += '-x' + res += "-x" else: - res += tmp + 'x' + res += tmp + "x" else: tmp += st[i] else: tmp += st[i] if i + 1 == len(st): if int(tmp) == 1: - res = 'x' + res = "x" elif int(tmp) == -1: - res = '-x' + res = "-x" else: - res += tmp + 'x' + res += tmp + "x" if iszero == 0: - res = 'W' + res = "W" else: - res += '+W' + res += "+W" print(res) diff --git a/BOJ/Gold/17387/main.py b/BOJ/Gold/17387/main.py index 4f87488..1ba2eae 100644 --- a/BOJ/Gold/17387/main.py +++ b/BOJ/Gold/17387/main.py @@ -9,10 +9,10 @@ def ccw(p1, p2, p3): return v1[0] * v2[1] - v1[1] * v2[0] -''' +""" v1[0] v1[1] v2[0] v2[1] -''' +""" def cross(p1, p2, p3, p4): diff --git a/BOJ/Gold/1753/Legacy/ver1.py b/BOJ/Gold/1753/Legacy/ver1.py index e10797e..86259da 100644 --- a/BOJ/Gold/1753/Legacy/ver1.py +++ b/BOJ/Gold/1753/Legacy/ver1.py @@ -21,6 +21,6 @@ for i in d: if i == INF: - print('INF') + print("INF") else: print(i) diff --git a/BOJ/Gold/1753/main.py b/BOJ/Gold/1753/main.py index 07094b0..acbbb1b 100644 --- a/BOJ/Gold/1753/main.py +++ b/BOJ/Gold/1753/main.py @@ -30,6 +30,6 @@ for i in d: if i == INF: - print('INF') + print("INF") else: print(i) diff --git a/BOJ/Gold/1759/main.py b/BOJ/Gold/1759/main.py index 9d1cb1c..ece7d63 100644 --- a/BOJ/Gold/1759/main.py +++ b/BOJ/Gold/1759/main.py @@ -6,7 +6,7 @@ L, C = map(int, read().split()) S = sorted(map(str, read().split())) -moum = set('aeiou') +moum = set("aeiou") for i in combinations(S, L): cntmoum = 0 @@ -17,4 +17,4 @@ else: cntjaum += 1 if cntmoum >= 1 and cntjaum >= 2: - print(''.join(i)) + print("".join(i)) diff --git a/BOJ/Gold/1823/main.py b/BOJ/Gold/1823/main.py index e6cb4ea..4d57c89 100644 --- a/BOJ/Gold/1823/main.py +++ b/BOJ/Gold/1823/main.py @@ -17,22 +17,9 @@ def solution(idx1, idx2, cnt): if dp[idx1][idx2]: return dp[idx1][idx2] dp[idx1][idx2] = max( - solution( - idx1 + - 1, - idx2, - cnt + - 1) + - cnt * - l[idx1], - solution( - idx1, - idx2 - - 1, - cnt + - 1) + - cnt * - l[idx2]) + solution(idx1 + 1, idx2, cnt + 1) + cnt * l[idx1], + solution(idx1, idx2 - 1, cnt + 1) + cnt * l[idx2], + ) return dp[idx1][idx2] diff --git a/BOJ/Gold/20058/main.py b/BOJ/Gold/20058/main.py index 1e6fe88..6a79204 100644 --- a/BOJ/Gold/20058/main.py +++ b/BOJ/Gold/20058/main.py @@ -9,7 +9,7 @@ def simulation(board, l, L): new_board = [[0] * l for _ in range(l)] - r_size = 2 ** L + r_size = 2**L for y in range(0, l, r_size): for x in range(0, l, r_size): for i in range(r_size): @@ -64,7 +64,7 @@ def BFS(board, l): N, Q = map(int, read().split()) -l = 2 ** N +l = 2**N board = [list(map(int, read().split())) for _ in range(l)] sim = list(map(int, read().split())) for L in sim: diff --git a/BOJ/Gold/2042/main.py b/BOJ/Gold/2042/main.py index 59aa9f2..ddfddac 100644 --- a/BOJ/Gold/2042/main.py +++ b/BOJ/Gold/2042/main.py @@ -8,8 +8,9 @@ def init(node, start, end): tree[node] = l[start] return tree[node] else: - tree[node] = init(node * 2, start, (start + end) // 2) + \ - init(node * 2 + 1, (start + end) // 2 + 1, end) + tree[node] = init(node * 2, start, (start + end) // 2) + init( + node * 2 + 1, (start + end) // 2 + 1, end + ) return tree[node] @@ -27,8 +28,9 @@ def segSum(node, start, end, left, right): return 0 if left <= start and end <= right: return tree[node] - return segSum(node * 2, start, (start + end) // 2, left, right) + \ - segSum(node * 2 + 1, (start + end) // 2 + 1, end, left, right) + return segSum(node * 2, start, (start + end) // 2, left, right) + segSum( + node * 2 + 1, (start + end) // 2 + 1, end, left, right + ) N, M, K = map(int, read().split()) diff --git a/BOJ/Gold/2174/main.py b/BOJ/Gold/2174/main.py index cb8c87d..9af1d9e 100644 --- a/BOJ/Gold/2174/main.py +++ b/BOJ/Gold/2174/main.py @@ -37,12 +37,13 @@ def goForward(robotNo, cnt): nx = x + ang[0] * i ny = y + ang[1] * i if not (0 <= nx < A) or not (0 <= ny < B): - print('Robot ' + str(robotNo + 1) + ' crashes into the wall') + print("Robot " + str(robotNo + 1) + " crashes into the wall") status = False break if G[nx][ny][0] != 0: - print('Robot ' + str(robotNo + 1) + - ' crashes into robot ' + str(G[nx][ny][0])) + print( + "Robot " + str(robotNo + 1) + " crashes into robot " + str(G[nx][ny][0]) + ) status = False break if status: @@ -57,7 +58,7 @@ def goForward(robotNo, cnt): G = [[[0, 0, 0] for _ in range(B)] for _ in range(A)] pos = [] -ang = {'E': [1, 0], 'N': [0, 1], 'W': [-1, 0], 'S': [0, -1]} +ang = {"E": [1, 0], "N": [0, 1], "W": [-1, 0], "S": [0, -1]} for i in range(M): a, b, c = map(str, read().split()) @@ -72,19 +73,19 @@ def goForward(robotNo, cnt): status = True for command in commands: - if command[1] == 'L': + if command[1] == "L": robotNo = int(command[0]) - 1 cnt = int(command[2]) turnLeft(robotNo, cnt) - elif command[1] == 'R': + elif command[1] == "R": robotNo = int(command[0]) - 1 cnt = int(command[2]) turnRight(robotNo, cnt) - elif command[1] == 'F': + elif command[1] == "F": robotNo = int(command[0]) - 1 cnt = int(command[2]) status = goForward(robotNo, cnt) if not status: break if status: - print('OK') + print("OK") diff --git a/BOJ/Gold/2239/main.py b/BOJ/Gold/2239/main.py index fab2053..1663162 100644 --- a/BOJ/Gold/2239/main.py +++ b/BOJ/Gold/2239/main.py @@ -40,7 +40,7 @@ def DFS(idx): if len(target) == idx: for i in range(9): for j in range(9): - print(l[i][j], end='') + print(l[i][j], end="") print() exit() x, y = target[idx] diff --git a/BOJ/Gold/2251/main.py b/BOJ/Gold/2251/main.py index 8a86f05..b453ccf 100644 --- a/BOJ/Gold/2251/main.py +++ b/BOJ/Gold/2251/main.py @@ -35,4 +35,4 @@ def pour(x, y): res.sort() for i in res: - print(i, end=' ') + print(i, end=" ") diff --git a/BOJ/Gold/2447/main.py b/BOJ/Gold/2447/main.py index 7cab887..7c92dde 100644 --- a/BOJ/Gold/2447/main.py +++ b/BOJ/Gold/2447/main.py @@ -5,16 +5,16 @@ def recur(N): if N == 1: - return ['*'] + return ["*"] tmp = recur(N // 3) l = [] for t in tmp: l.append(t * 3) for t in tmp: - l.append(t + ' ' * (N // 3) + t) + l.append(t + " " * (N // 3) + t) for t in tmp: l.append(t * 3) return l -print('\n'.join(recur(N))) +print("\n".join(recur(N))) diff --git a/BOJ/Gold/3055/main.py b/BOJ/Gold/3055/main.py index 4a12fea..8c32daf 100644 --- a/BOJ/Gold/3055/main.py +++ b/BOJ/Gold/3055/main.py @@ -4,15 +4,15 @@ read = sys.stdin.readline R, C = map(int, read().split()) -G = [['' for _ in range(C)] for _ in range(R)] +G = [["" for _ in range(C)] for _ in range(R)] time = [[0 for _ in range(C)] for _ in range(R)] for i in range(R): G[i] = list(read().rstrip()) for j in range(C): - if G[i][j] == 'D': + if G[i][j] == "D": D = (i, j) - elif G[i][j] == 'S': + elif G[i][j] == "S": S = (i, j) v1 = [1, 0, -1, 0] @@ -22,16 +22,16 @@ def BFS(): while q: x, y = q.popleft() - if G[D[0]][D[1]] == 'S': + if G[D[0]][D[1]] == "S": return time[D[0]][D[1]] for i in range(4): nx, ny = x + v1[i], y + v2[i] if 0 <= nx < R and 0 <= ny < C: - if (G[nx][ny] == '.' or G[nx][ny] == 'S') and G[x][y] == '*': - G[nx][ny] = '*' + if (G[nx][ny] == "." or G[nx][ny] == "S") and G[x][y] == "*": + G[nx][ny] = "*" q.append((nx, ny)) - elif (G[nx][ny] == '.' or G[nx][ny] == 'D') and G[x][y] == 'S': - G[nx][ny] = 'S' + elif (G[nx][ny] == "." or G[nx][ny] == "D") and G[x][y] == "S": + G[nx][ny] = "S" time[nx][ny] = time[x][y] + 1 q.append((nx, ny)) return "KAKTUS" @@ -40,7 +40,7 @@ def BFS(): q = deque([S]) for i in range(R): for j in range(C): - if G[i][j] == '*': + if G[i][j] == "*": q.append((i, j)) print(BFS()) diff --git a/BOJ/Gold/3109/Legacy/ver1.py b/BOJ/Gold/3109/Legacy/ver1.py index 9192eb7..4eb5e35 100644 --- a/BOJ/Gold/3109/Legacy/ver1.py +++ b/BOJ/Gold/3109/Legacy/ver1.py @@ -15,14 +15,14 @@ j = 0 ii = 0 while j < C - 1: - if l[i + ii][j + 1] == '.': + if l[i + ii][j + 1] == ".": dict[j + 1] = i + ii # l[i + ii][j + 1] = 'x' - elif i + ii + 1 < R and l[i + ii + 1][j + 1] == '.': + elif i + ii + 1 < R and l[i + ii + 1][j + 1] == ".": dict[j + 1] = i + ii + 1 # l[i + ii + 1][j + 1] = 'x' ii += 1 - elif i + ii - 1 >= 0 and l[i + ii - 1][j + 1] == '.': + elif i + ii - 1 >= 0 and l[i + ii - 1][j + 1] == ".": dict[j + 1] = i + ii - 1 # l[i + ii - 1][j + 1] = 'x' ii -= 1 @@ -33,5 +33,5 @@ if j >= C - 1: for k in range(1, C): print(k) - l[dict[k]][k] = 'x' + l[dict[k]][k] = "x" cnt += 1 diff --git a/BOJ/Gold/3109/main.py b/BOJ/Gold/3109/main.py index 6b27ca6..d0e0d7e 100644 --- a/BOJ/Gold/3109/main.py +++ b/BOJ/Gold/3109/main.py @@ -17,8 +17,7 @@ def DFS(i, j): if j == C - 1: return True for v in vec: - if 0 <= i + v < R and l[i + v][j + - 1] == '.' and not visit[i + v][j + 1]: + if 0 <= i + v < R and l[i + v][j + 1] == "." and not visit[i + v][j + 1]: visit[i + v][j + 1] = True if DFS(i + v, j + 1): return True @@ -27,7 +26,7 @@ def DFS(i, j): res = 0 for i in range(R): - if l[i][0] == '.': + if l[i][0] == ".": if DFS(i, 0): res += 1 diff --git a/BOJ/Gold/3190/main.py b/BOJ/Gold/3190/main.py index 30f5767..279e5d5 100644 --- a/BOJ/Gold/3190/main.py +++ b/BOJ/Gold/3190/main.py @@ -24,16 +24,15 @@ dir_x, dir_y = 1, 0 time = 0 -rightTurn = {(1, 0): (0, 1), (0, 1): (-1, 0), - (-1, 0): (0, -1), (0, -1): (1, 0)} +rightTurn = {(1, 0): (0, 1), (0, 1): (-1, 0), (-1, 0): (0, -1), (0, -1): (1, 0)} leftTurn = {(1, 0): (0, -1), (0, -1): (-1, 0), (-1, 0): (0, 1), (0, 1): (1, 0)} while True: x, y = snake[0] if time in timeline.keys(): - if timeline[time] == 'L': + if timeline[time] == "L": dir_x, dir_y = leftTurn[(dir_x, dir_y)] - elif timeline[time] == 'D': + elif timeline[time] == "D": dir_x, dir_y = rightTurn[(dir_x, dir_y)] nx, ny = x + dir_x, y + dir_y if (nx, ny) in snake: diff --git a/BOJ/Gold/5430/main.py b/BOJ/Gold/5430/main.py index 06cb68d..19e91dd 100644 --- a/BOJ/Gold/5430/main.py +++ b/BOJ/Gold/5430/main.py @@ -9,15 +9,15 @@ n = int(read()) l = read().rstrip() if n > 0: - d = deque(list(map(str, l[1:-1].split(',')))) + d = deque(list(map(str, l[1:-1].split(",")))) else: d = deque() status = True rev = 0 for command in commands: - if command == 'R': + if command == "R": rev += 1 - elif command == 'D': + elif command == "D": if n > 0: if rev % 2 == 0: d.popleft() @@ -26,9 +26,9 @@ n -= 1 else: status = False - print('error') + print("error") break if rev % 2 == 1: d.reverse() if status: - print('[' + ','.join(d) + ']') + print("[" + ",".join(d) + "]") diff --git a/BOJ/Gold/7569/main.py b/BOJ/Gold/7569/main.py index 26728fd..79b17b9 100644 --- a/BOJ/Gold/7569/main.py +++ b/BOJ/Gold/7569/main.py @@ -14,8 +14,15 @@ def bfs(g): z2 = z1 + v1[i] y2 = y1 + v2[i] x2 = x1 + v3[i] - if 0 <= x2 and x2 < M and 0 <= y2 and y2 < N and 0 <= z2 and z2 < H and g[ - z2][y2][x2] == 0: + if ( + 0 <= x2 + and x2 < M + and 0 <= y2 + and y2 < N + and 0 <= z2 + and z2 < H + and g[z2][y2][x2] == 0 + ): q.append([z2, y2, x2]) g[z2][y2][x2] = g[z1][y1][x1] + 1 diff --git a/BOJ/Gold/7662/Legacy/ver1.py b/BOJ/Gold/7662/Legacy/ver1.py index e9cae87..07789aa 100644 --- a/BOJ/Gold/7662/Legacy/ver1.py +++ b/BOJ/Gold/7662/Legacy/ver1.py @@ -10,9 +10,9 @@ for _ in range(k): a, b = read().split() b = int(b) - if a == 'I': + if a == "I": Q.append(b) - elif a == 'D': + elif a == "D": if Q: if b == -1: tmp = min(Q) @@ -23,4 +23,4 @@ if Q: print(max(Q), min(Q)) else: - print('EMPTY') + print("EMPTY") diff --git a/BOJ/Gold/7662/main.py b/BOJ/Gold/7662/main.py index aaef52f..b100372 100644 --- a/BOJ/Gold/7662/main.py +++ b/BOJ/Gold/7662/main.py @@ -11,11 +11,11 @@ for key in range(k): a, b = read().split() b = int(b) - if a == 'I': + if a == "I": heapq.heappush(mheap, (b, key)) heapq.heappush(Mheap, (-b, key)) visit[key] = True - elif a == 'D': + elif a == "D": if b == -1: while mheap and not visit[mheap[0][1]]: heapq.heappop(mheap) @@ -35,4 +35,4 @@ if mheap and Mheap: print(-Mheap[0][0], mheap[0][0]) else: - print('EMPTY') + print("EMPTY") diff --git a/BOJ/Gold/9328/main.py b/BOJ/Gold/9328/main.py index c00d590..7815fff 100644 --- a/BOJ/Gold/9328/main.py +++ b/BOJ/Gold/9328/main.py @@ -17,24 +17,23 @@ def BFS(x, y): for i in range(4): nx, ny = x + v1[i], y + v2[i] if 0 <= nx < h + 2 and 0 <= ny < w + 2 and not visit[nx][ny]: - if l[nx][ny] == '.': + if l[nx][ny] == ".": visit[nx][ny] = True q.append((nx, ny)) elif l[nx][ny].islower(): - door[ord(l[nx][ny]) - ord('a')] = True - visit = [[False for _ in range(w + 2)] - for _ in range(h + 2)] - l[nx][ny] = '.' + door[ord(l[nx][ny]) - ord("a")] = True + visit = [[False for _ in range(w + 2)] for _ in range(h + 2)] + l[nx][ny] = "." q.append((nx, ny)) elif l[nx][ny].isupper(): - if door[ord(l[nx][ny]) - ord('A')]: + if door[ord(l[nx][ny]) - ord("A")]: visit[nx][ny] = True - l[nx][ny] = '.' + l[nx][ny] = "." q.append((nx, ny)) - elif l[nx][ny] == '$': + elif l[nx][ny] == "$": res += 1 visit[nx][ny] = True - l[nx][ny] = '.' + l[nx][ny] = "." q.append((nx, ny)) print(res) @@ -47,16 +46,15 @@ def BFS(x, y): keys = list(read().strip()) door = [False for _ in range(26)] for key in keys: - if key != '0': - door[ord(key) - ord('a')] = True + if key != "0": + door[ord(key) - ord("a")] = True for i in range(h): for j in range(w): - if ord('A') <= ord(l[i][j]) <= ord( - 'Z') and door[ord(l[i][j]) - ord('A')]: - l[i][j] = '.' + if ord("A") <= ord(l[i][j]) <= ord("Z") and door[ord(l[i][j]) - ord("A")]: + l[i][j] = "." for i in l: - i.insert(0, '.') - i.append('.') - l.insert(0, ['.'] * (w + 2)) - l.append(['.'] * (w + 2)) + i.insert(0, ".") + i.append(".") + l.insert(0, ["."] * (w + 2)) + l.append(["."] * (w + 2)) BFS(0, 0) diff --git a/BOJ/Gold/9466/main.py b/BOJ/Gold/9466/main.py index ea505ef..a869afc 100644 --- a/BOJ/Gold/9466/main.py +++ b/BOJ/Gold/9466/main.py @@ -1,7 +1,7 @@ import sys read = sys.stdin.readline -sys.setrecursionlimit(10 ** 6) +sys.setrecursionlimit(10**6) T = int(read()) @@ -12,7 +12,7 @@ def DFS(pos): tmp.append(pos) if visit[l[pos]]: if l[pos] in tmp: - res += tmp[tmp.index(l[pos]):] + res += tmp[tmp.index(l[pos]) :] return else: DFS(l[pos]) diff --git a/BOJ/Gold/9553/Legacy/ver1.py b/BOJ/Gold/9553/Legacy/ver1.py index 9a69647..0a155dd 100644 --- a/BOJ/Gold/9553/Legacy/ver1.py +++ b/BOJ/Gold/9553/Legacy/ver1.py @@ -66,12 +66,8 @@ def returnAvg(x1, y1, x2, y2, angleHitList): angleCheckList = [i / 100 for i in range(36001)] for i in range(len(x1)): angleHitList = checkHit( - angleCheckList, - x1[i], - y1[i], - x2[i], - y2[i], - angleHitList) + angleCheckList, x1[i], y1[i], x2[i], y2[i], angleHitList + ) return mean(angleHitList) @@ -97,11 +93,11 @@ def returnAvg(x1, y1, x2, y2, angleHitList): for i in range(T): angleHitList = [0 for i in range(36001)] - tmpx1 = x1[N[i - 1] * (i):N[i] * (i + 1)] - tmpy1 = y1[N[i - 1] * (i):N[i] * (i + 1)] - tmpx2 = x2[N[i - 1] * (i):N[i] * (i + 1)] - tmpy2 = y2[N[i - 1] * (i):N[i] * (i + 1)] + tmpx1 = x1[N[i - 1] * (i) : N[i] * (i + 1)] + tmpy1 = y1[N[i - 1] * (i) : N[i] * (i + 1)] + tmpx2 = x2[N[i - 1] * (i) : N[i] * (i + 1)] + tmpy2 = y2[N[i - 1] * (i) : N[i] * (i + 1)] avg.append(returnAvg(tmpx1, tmpy1, tmpx2, tmpy2, angleHitList)) for i in range(T): - print(format(avg[i], '.5f')) + print(format(avg[i], ".5f")) diff --git a/BOJ/Gold/9553/Legacy/ver2.py b/BOJ/Gold/9553/Legacy/ver2.py index 6a2c488..fea55f2 100644 --- a/BOJ/Gold/9553/Legacy/ver2.py +++ b/BOJ/Gold/9553/Legacy/ver2.py @@ -60,5 +60,5 @@ def returnAvg(x1, y1, x2, y2): y1.append(b) x2.append(c) y2.append(d) - avg = (returnAvg(x1, y1, x2, y2)) - print(format(avg, '.5f')) + avg = returnAvg(x1, y1, x2, y2) + print(format(avg, ".5f")) diff --git a/BOJ/Gold/9553/main.py b/BOJ/Gold/9553/main.py index 86a6db4..627c02e 100644 --- a/BOJ/Gold/9553/main.py +++ b/BOJ/Gold/9553/main.py @@ -2,10 +2,22 @@ def probability(x1, y1, x2, y2): - return (math.acos((x1 * x2 + y1 * y2) / - math.sqrt((x1**2 + y1**2) * (x2**2 + y2**2)))) / (2 * math.pi) + return ( + math.acos( + (x1 * x2 + y1 * y2) / math.sqrt((x1**2 + y1**2) * (x2**2 + y2**2)) + ) + ) / (2 * math.pi) for tc in range(int(input())): - print(format(sum([probability(*list(map(int, input().split()))) - for i in range(int(input()))]), ".5f")) + print( + format( + sum( + [ + probability(*list(map(int, input().split()))) + for i in range(int(input())) + ] + ), + ".5f", + ) + ) diff --git a/BOJ/Platinum/1067/main.py b/BOJ/Platinum/1067/main.py index 10b4600..6899149 100644 --- a/BOJ/Platinum/1067/main.py +++ b/BOJ/Platinum/1067/main.py @@ -12,14 +12,16 @@ def fft(sig, inv): sig_even = fft(sig[0::2], 0) sig_odd = fft(sig[1::2], 0) W = [exp(2j * pi * i / N) for i in range(N // 2)] - return [sig_even[i] + W[i] * sig_odd[i] - for i in range(N // 2)] + [sig_even[i] - W[i] * sig_odd[i] for i in range(N // 2)] + return [sig_even[i] + W[i] * sig_odd[i] for i in range(N // 2)] + [ + sig_even[i] - W[i] * sig_odd[i] for i in range(N // 2) + ] elif inv == 1: sig_even = fft(sig[0::2], 1) sig_odd = fft(sig[1::2], 1) W = [exp(-2j * pi * i / N) for i in range(N // 2)] - return [sig_even[i] + W[i] * sig_odd[i] - for i in range(N // 2)] + [sig_even[i] - W[i] * sig_odd[i] for i in range(N // 2)] + return [sig_even[i] + W[i] * sig_odd[i] for i in range(N // 2)] + [ + sig_even[i] - W[i] * sig_odd[i] for i in range(N // 2) + ] def mul(a, b, N): diff --git a/BOJ/Platinum/1510 (Incompleted)/Legacy/ver1.py b/BOJ/Platinum/1510 (Incompleted)/Legacy/ver1.py index 9329223..7c4bce9 100644 --- a/BOJ/Platinum/1510 (Incompleted)/Legacy/ver1.py +++ b/BOJ/Platinum/1510 (Incompleted)/Legacy/ver1.py @@ -10,10 +10,15 @@ def euc(x1, y1, x2, y2): for y2 in range(n): for x3 in range(m): for y3 in range(n): - if ((x1 != x2) or (y1 != y2)) and ((x1 != x3) or ( - y1 != y3)) and ((x2 != x3) or (y2 != y3)): - if not ((x1 == x2 and x1 == x3 and x2 == x3) or ( - y1 == y2 and y1 == y3 and y2 == y3)): + if ( + ((x1 != x2) or (y1 != y2)) + and ((x1 != x3) or (y1 != y3)) + and ((x2 != x3) or (y2 != y3)) + ): + if not ( + (x1 == x2 and x1 == x3 and x2 == x3) + or (y1 == y2 and y1 == y3 and y2 == y3) + ): l1 = euc(x1, y1, x2, y2) l2 = euc(x2, y2, x3, y3) l3 = euc(x1, y1, x3, y3) diff --git a/BOJ/Platinum/15807/main.py b/BOJ/Platinum/15807/main.py index 3bcb56c..83e74ad 100644 --- a/BOJ/Platinum/15807/main.py +++ b/BOJ/Platinum/15807/main.py @@ -14,8 +14,7 @@ for y in range(1, 3002): for x in range(1, 3002): - axis[x][y] = diag1[3002 + x - y] + \ - axis[x][y - 1] + diag2[x + y] + light[x][y] + axis[x][y] = diag1[3002 + x - y] + axis[x][y - 1] + diag2[x + y] + light[x][y] diag1[3002 + x - y] += light[x][y] diag2[x + y] += light[x][y] diff --git a/BOJ/Platinum/9206/main.py b/BOJ/Platinum/9206/main.py index 6fe489e..c19fa9c 100644 --- a/BOJ/Platinum/9206/main.py +++ b/BOJ/Platinum/9206/main.py @@ -3,7 +3,7 @@ def f(a, b, h, x): - return a * math.e ** (- ((x) ** 2)) + b * x ** (0.5) + return a * math.e ** (-((x) ** 2)) + b * x ** (0.5) def integration(a, b, h): @@ -14,7 +14,7 @@ def integration(a, b, h): befx = (i - 1) / resol * h tmpx = i / resol * h tmpy = (f(a, b, h, befx) + f(a, b, h, tmpx)) / 2 - V += tmpy ** 2 * math.pi / resol * h + V += tmpy**2 * math.pi / resol * h return V diff --git a/BOJ/Silver/1010/main.py b/BOJ/Silver/1010/main.py index 6ab2861..6d04673 100644 --- a/BOJ/Silver/1010/main.py +++ b/BOJ/Silver/1010/main.py @@ -11,5 +11,6 @@ M.append(int(b)) for i in range(T): - print(int(math.factorial( - M[i]) / (math.factorial(M[i] - N[i]) * math.factorial(N[i])))) + print( + int(math.factorial(M[i]) / (math.factorial(M[i] - N[i]) * math.factorial(N[i]))) + ) diff --git a/BOJ/Silver/1018/main.py b/BOJ/Silver/1018/main.py index 6244d39..08097f0 100644 --- a/BOJ/Silver/1018/main.py +++ b/BOJ/Silver/1018/main.py @@ -12,14 +12,14 @@ for i in range(a, a + 8): for j in range(b, b + 8): if (i + j) % 2 == 0: - if org[i][j] != 'W': + if org[i][j] != "W": idx1 += 1 - if org[i][j] != 'B': + if org[i][j] != "B": idx2 += 1 else: - if org[i][j] != 'B': + if org[i][j] != "B": idx1 += 1 - if org[i][j] != 'W': + if org[i][j] != "W": idx2 += 1 cnt.append(min(idx1, idx2)) diff --git a/BOJ/Silver/1058/main.py b/BOJ/Silver/1058/main.py index 3652341..60b97ea 100644 --- a/BOJ/Silver/1058/main.py +++ b/BOJ/Silver/1058/main.py @@ -9,7 +9,7 @@ for i in range(N): s = read().rstrip() for j, k in enumerate(s): - if k == 'Y': + if k == "Y": g[i].append(j) diff --git a/BOJ/Silver/1074/Legacy/ver1.py b/BOJ/Silver/1074/Legacy/ver1.py index 5caa43f..639fc97 100644 --- a/BOJ/Silver/1074/Legacy/ver1.py +++ b/BOJ/Silver/1074/Legacy/ver1.py @@ -22,7 +22,7 @@ def zzz(x, y, n): N, c, r = map(int, read().split()) -l = [[-1 for _ in range(2 ** N)] for _ in range(2 ** N)] +l = [[-1 for _ in range(2**N)] for _ in range(2**N)] -zzz(0, 0, 2 ** N) +zzz(0, 0, 2**N) print(l[c][r]) diff --git a/BOJ/Silver/1080/main.py b/BOJ/Silver/1080/main.py index f2f7a77..6aa7ed8 100644 --- a/BOJ/Silver/1080/main.py +++ b/BOJ/Silver/1080/main.py @@ -6,10 +6,10 @@ def cal(mat, x, y): for i in range(3): for j in range(3): - if mat[x + i][y + j] == '1': - mat[x + i][y + j] = '0' + if mat[x + i][y + j] == "1": + mat[x + i][y + j] = "0" else: - mat[x + i][y + j] = '1' + mat[x + i][y + j] = "1" N, M = map(int, read().split()) diff --git a/BOJ/Silver/10816/main.py b/BOJ/Silver/10816/main.py index adfca15..b79b10a 100644 --- a/BOJ/Silver/10816/main.py +++ b/BOJ/Silver/10816/main.py @@ -12,6 +12,6 @@ for i in scard: if i in ndict: - print(ndict[i], end=' ') + print(ndict[i], end=" ") else: - print(0, end=' ') + print(0, end=" ") diff --git a/BOJ/Silver/10828/Legacy/ver1.py b/BOJ/Silver/10828/Legacy/ver1.py index 1829acf..dc6a178 100644 --- a/BOJ/Silver/10828/Legacy/ver1.py +++ b/BOJ/Silver/10828/Legacy/ver1.py @@ -3,22 +3,22 @@ for _ in range(N): l = input().split() - if l[0] == 'push': + if l[0] == "push": stack.append(int(l[1])) - elif l[0] == 'pop': + elif l[0] == "pop": if len(stack) > 0: print(stack[-1]) del stack[-1] else: print(-1) - elif l[0] == 'size': + elif l[0] == "size": print(len(stack)) - elif l[0] == 'empty': + elif l[0] == "empty": if len(stack) == 0: print(1) else: print(0) - elif l[0] == 'top': + elif l[0] == "top": if len(stack) > 0: print(stack[-1]) else: diff --git a/BOJ/Silver/10828/main.py b/BOJ/Silver/10828/main.py index 699cd4e..ae208c9 100644 --- a/BOJ/Silver/10828/main.py +++ b/BOJ/Silver/10828/main.py @@ -5,21 +5,21 @@ for _ in range(N): l = sys.stdin.readline().split() - if l[0] == 'push': + if l[0] == "push": stack.append(int(l[1])) - elif l[0] == 'pop': + elif l[0] == "pop": if len(stack) > 0: print(stack.pop()) else: print(-1) - elif l[0] == 'size': + elif l[0] == "size": print(len(stack)) - elif l[0] == 'empty': + elif l[0] == "empty": if len(stack) == 0: print(1) else: print(0) - elif l[0] == 'top': + elif l[0] == "top": if len(stack) > 0: print(stack[-1]) else: diff --git a/BOJ/Silver/10845/main.py b/BOJ/Silver/10845/main.py index 4367667..ed23908 100644 --- a/BOJ/Silver/10845/main.py +++ b/BOJ/Silver/10845/main.py @@ -5,27 +5,27 @@ for _ in range(N): l = sys.stdin.readline().split() - if l[0] == 'push': + if l[0] == "push": queue.append(int(l[1])) - elif l[0] == 'pop': + elif l[0] == "pop": if len(queue) > 0: print(queue[0]) del queue[0] else: print(-1) - elif l[0] == 'size': + elif l[0] == "size": print(len(queue)) - elif l[0] == 'empty': + elif l[0] == "empty": if len(queue) == 0: print(1) else: print(0) - elif l[0] == 'front': + elif l[0] == "front": if len(queue) > 0: print(queue[0]) else: print(-1) - elif l[0] == 'back': + elif l[0] == "back": if len(queue) > 0: print(queue[-1]) else: diff --git a/BOJ/Silver/10866/main.py b/BOJ/Silver/10866/main.py index b4cfc5c..6fc52d3 100644 --- a/BOJ/Silver/10866/main.py +++ b/BOJ/Silver/10866/main.py @@ -5,35 +5,35 @@ for _ in range(N): l = sys.stdin.readline().split() - if l[0] == 'push_front': + if l[0] == "push_front": Deque.insert(0, int(l[1])) - elif l[0] == 'push_back': + elif l[0] == "push_back": Deque.append(int(l[1])) - elif l[0] == 'pop_front': + elif l[0] == "pop_front": if len(Deque) > 0: print(Deque[0]) del Deque[0] else: print(-1) - elif l[0] == 'pop_back': + elif l[0] == "pop_back": if len(Deque) > 0: print(Deque[-1]) del Deque[-1] else: print(-1) - elif l[0] == 'size': + elif l[0] == "size": print(len(Deque)) - elif l[0] == 'empty': + elif l[0] == "empty": if len(Deque) == 0: print(1) else: print(0) - elif l[0] == 'front': + elif l[0] == "front": if len(Deque) > 0: print(Deque[0]) else: print(-1) - elif l[0] == 'back': + elif l[0] == "back": if len(Deque) > 0: print(Deque[-1]) else: diff --git a/BOJ/Silver/11399/main.py b/BOJ/Silver/11399/main.py index 7a31586..0033f5e 100644 --- a/BOJ/Silver/11399/main.py +++ b/BOJ/Silver/11399/main.py @@ -7,6 +7,6 @@ res = 0 for i in range(N): - res += sum(l[0:i + 1]) + res += sum(l[0 : i + 1]) print(res) diff --git a/BOJ/Silver/11660/main.py b/BOJ/Silver/11660/main.py index 9d8d6a4..9d2b1cc 100644 --- a/BOJ/Silver/11660/main.py +++ b/BOJ/Silver/11660/main.py @@ -11,8 +11,7 @@ for i in range(N): for j in range(N): - dp[i + 1][j + 1] = l[i + 1][j + 1] + \ - dp[i + 1][j] + dp[i][j + 1] - dp[i][j] + dp[i + 1][j + 1] = l[i + 1][j + 1] + dp[i + 1][j] + dp[i][j + 1] - dp[i][j] for _ in range(M): x1, y1, x2, y2 = map(int, read().split()) diff --git a/BOJ/Silver/11723/main.py b/BOJ/Silver/11723/main.py index ec44085..6b426d6 100644 --- a/BOJ/Silver/11723/main.py +++ b/BOJ/Silver/11723/main.py @@ -7,24 +7,24 @@ for _ in range(N): tmp = read().split() - if tmp[0] == 'add': + if tmp[0] == "add": l.add(int(tmp[1])) - elif tmp[0] == 'remove': + elif tmp[0] == "remove": try: l.remove(int(tmp[1])) except BaseException: continue - elif tmp[0] == 'check': + elif tmp[0] == "check": if int(tmp[1]) in l: print(1) else: print(0) - elif tmp[0] == 'toggle': + elif tmp[0] == "toggle": if int(tmp[1]) in l: l.remove(int(tmp[1])) else: l.add(int(tmp[1])) - elif tmp[0] == 'all': + elif tmp[0] == "all": l = set([i for i in range(1, 21)]) - elif tmp[0] == 'empty': + elif tmp[0] == "empty": l = set() diff --git a/BOJ/Silver/11866/Legacy/ver1.py b/BOJ/Silver/11866/Legacy/ver1.py index eb910c4..4bbebab 100644 --- a/BOJ/Silver/11866/Legacy/ver1.py +++ b/BOJ/Silver/11866/Legacy/ver1.py @@ -2,7 +2,7 @@ l = [1] + [0 for i in range(N)] -print('<', end='') +print("<", end="") tmp = 0 for i in range(N): localtmp = 0 @@ -14,7 +14,7 @@ tmp = tmp % N l[tmp] = 1 if i < N - 1: - print(str(tmp) + ',', end=' ') + print(str(tmp) + ",", end=" ") else: - print(str(tmp), end='') -print('>') + print(str(tmp), end="") +print(">") diff --git a/BOJ/Silver/11866/main.py b/BOJ/Silver/11866/main.py index 536e4f7..a222591 100644 --- a/BOJ/Silver/11866/main.py +++ b/BOJ/Silver/11866/main.py @@ -13,8 +13,8 @@ queue.append(queue.popleft()) answer.append(queue.popleft()) -print("<", end='') +print("<", end="") for i in range(len(answer) - 1): - print("%d, " % answer[i], end='') -print(answer[-1], end='') + print("%d, " % answer[i], end="") +print(answer[-1], end="") print(">") diff --git a/BOJ/Silver/1193/main.py b/BOJ/Silver/1193/main.py index 6b0bcc7..7c3377b 100644 --- a/BOJ/Silver/1193/main.py +++ b/BOJ/Silver/1193/main.py @@ -4,7 +4,7 @@ def solution(X): if X == 1: - print('1/1') + print("1/1") else: est_n = int(math.sqrt(2 * X)) if est_n * (est_n - 1) < 2 * X <= est_n * (est_n + 1): @@ -21,7 +21,7 @@ def solution(X): x, y = 1, n x += m - X y -= m - X - print(str(x) + '/' + str(y)) + print(str(x) + "/" + str(y)) if __name__ == "__main__": diff --git a/BOJ/Silver/1213/main.py b/BOJ/Silver/1213/main.py index 6877347..3934b04 100644 --- a/BOJ/Silver/1213/main.py +++ b/BOJ/Silver/1213/main.py @@ -4,8 +4,8 @@ s = sorted(map(str, sys.stdin.readline().rstrip())) c = Counter(s) cnt = 0 -mid = '' -res = '' +mid = "" +res = "" for i in c: if c[i] % 2 != 0: diff --git a/BOJ/Silver/12208/main.py b/BOJ/Silver/12208/main.py index 704cffe..8fb2985 100644 --- a/BOJ/Silver/12208/main.py +++ b/BOJ/Silver/12208/main.py @@ -5,12 +5,16 @@ def n2n(i, j, dir): while True: - if not (((0 <= i < N) and (0 <= j < N)) and ( - (0 <= i + dir[1] < N) and (0 <= j + dir[0] < N))): + if not ( + ((0 <= i < N) and (0 <= j < N)) + and ((0 <= i + dir[1] < N) and (0 <= j + dir[0] < N)) + ): break elif not G[i][j] == 0: - if G[i + dir[1]][j + dir[0] - ] == G[i][j] and not visited[i + dir[1]][j + dir[0]]: + if ( + G[i + dir[1]][j + dir[0]] == G[i][j] + and not visited[i + dir[1]][j + dir[0]] + ): G[i + dir[1]][j + dir[0]] = G[i][j] * 2 G[i][j] = 0 visited[i + dir[1]][j + dir[0]] = True @@ -40,17 +44,17 @@ def simulation(dir): # 0, 1, 2, 3 x_r = ((N - 2, -1, -1), (0, N, 1), (1, N, 1), (0, N, 1)) y_r = ((0, N, 1), (1, N, 1), (0, N, 1), (N - 2, -1, -1)) G = [[0 for _ in range(N)] for _ in range(N)] - print('Case #' + str(i + 1) + ':') + print("Case #" + str(i + 1) + ":") for i in range(N): G[i] = list(map(int, read().split())) visited = [[False for _ in range(N)] for _ in range(N)] - if dir == 'right': + if dir == "right": simulation(0) - elif dir == 'up': + elif dir == "up": simulation(1) - elif dir == 'left': + elif dir == "left": simulation(2) - elif dir == 'down': + elif dir == "down": simulation(3) for i in G: print(*i) diff --git a/BOJ/Silver/12209/main.py b/BOJ/Silver/12209/main.py index 704cffe..8fb2985 100644 --- a/BOJ/Silver/12209/main.py +++ b/BOJ/Silver/12209/main.py @@ -5,12 +5,16 @@ def n2n(i, j, dir): while True: - if not (((0 <= i < N) and (0 <= j < N)) and ( - (0 <= i + dir[1] < N) and (0 <= j + dir[0] < N))): + if not ( + ((0 <= i < N) and (0 <= j < N)) + and ((0 <= i + dir[1] < N) and (0 <= j + dir[0] < N)) + ): break elif not G[i][j] == 0: - if G[i + dir[1]][j + dir[0] - ] == G[i][j] and not visited[i + dir[1]][j + dir[0]]: + if ( + G[i + dir[1]][j + dir[0]] == G[i][j] + and not visited[i + dir[1]][j + dir[0]] + ): G[i + dir[1]][j + dir[0]] = G[i][j] * 2 G[i][j] = 0 visited[i + dir[1]][j + dir[0]] = True @@ -40,17 +44,17 @@ def simulation(dir): # 0, 1, 2, 3 x_r = ((N - 2, -1, -1), (0, N, 1), (1, N, 1), (0, N, 1)) y_r = ((0, N, 1), (1, N, 1), (0, N, 1), (N - 2, -1, -1)) G = [[0 for _ in range(N)] for _ in range(N)] - print('Case #' + str(i + 1) + ':') + print("Case #" + str(i + 1) + ":") for i in range(N): G[i] = list(map(int, read().split())) visited = [[False for _ in range(N)] for _ in range(N)] - if dir == 'right': + if dir == "right": simulation(0) - elif dir == 'up': + elif dir == "up": simulation(1) - elif dir == 'left': + elif dir == "left": simulation(2) - elif dir == 'down': + elif dir == "down": simulation(3) for i in G: print(*i) diff --git a/BOJ/Silver/1260/main.py b/BOJ/Silver/1260/main.py index 8c25927..421eeb2 100644 --- a/BOJ/Silver/1260/main.py +++ b/BOJ/Silver/1260/main.py @@ -5,7 +5,7 @@ def DFS(initPos): - print(initPos, end=' ') + print(initPos, end=" ") v[initPos] = True for i in g[initPos]: if not v[i]: @@ -18,7 +18,7 @@ def BFS(initPos): v[initPos] = True while q: tmp = q.popleft() - print(tmp, end=' ') + print(tmp, end=" ") for i in g[tmp]: if not v[i]: v[i] = True diff --git a/BOJ/Silver/12852/main.py b/BOJ/Silver/12852/main.py index edeee39..4c5e9ec 100644 --- a/BOJ/Silver/12852/main.py +++ b/BOJ/Silver/12852/main.py @@ -17,4 +17,4 @@ print(dp[N][0]) for i in dp[N][1][::-1]: - print(i, end=' ') + print(i, end=" ") diff --git a/BOJ/Silver/1402/main.py b/BOJ/Silver/1402/main.py index 42b1214..3c3cfd0 100644 --- a/BOJ/Silver/1402/main.py +++ b/BOJ/Silver/1402/main.py @@ -2,4 +2,4 @@ for i in range(T): A, B = map(int, input().split()) - print('yes') + print("yes") diff --git a/BOJ/Silver/1436/main.py b/BOJ/Silver/1436/main.py index b9e8508..d76023b 100644 --- a/BOJ/Silver/1436/main.py +++ b/BOJ/Silver/1436/main.py @@ -4,7 +4,7 @@ while N >= cnt: tmp += 1 - if '666' in str(tmp): + if "666" in str(tmp): cnt += 1 print(tmp) diff --git a/BOJ/Silver/14600/main.py b/BOJ/Silver/14600/main.py index eb2cd86..f9c052b 100644 --- a/BOJ/Silver/14600/main.py +++ b/BOJ/Silver/14600/main.py @@ -34,9 +34,9 @@ def tile(x, y, K, pos): tmp += 1 return tile(x, y, K - 1, 0) - tile(x, y + 2**(K - 1), K - 1, 1) - tile(x + 2**(K - 1), y, K - 1, 2) - tile(x + 2**(K - 1), y + 2**(K - 1), K - 1, 3) + tile(x, y + 2 ** (K - 1), K - 1, 1) + tile(x + 2 ** (K - 1), y, K - 1, 2) + tile(x + 2 ** (K - 1), y + 2 ** (K - 1), K - 1, 3) tile(x + 2**K // 4, y + 2**K // 4, K - 1, 4) @@ -51,5 +51,5 @@ def tile(x, y, K, pos): for i in l: for j in i: - print(j, end=' ') + print(j, end=" ") print() diff --git a/BOJ/Silver/1543/main.py b/BOJ/Silver/1543/main.py index 9f862cc..066d314 100644 --- a/BOJ/Silver/1543/main.py +++ b/BOJ/Silver/1543/main.py @@ -8,7 +8,7 @@ tmp = 0 while tmp <= len(s1) - len(s2): - if s1[tmp:tmp + len(s2)] == s2: + if s1[tmp : tmp + len(s2)] == s2: cnt += 1 tmp += len(s2) else: diff --git a/BOJ/Silver/15650/main.py b/BOJ/Silver/15650/main.py index 610d9f6..a924359 100644 --- a/BOJ/Silver/15650/main.py +++ b/BOJ/Silver/15650/main.py @@ -7,7 +7,7 @@ def DFS(start): if len(l) == M: - print(' '.join(map(str, l))) + print(" ".join(map(str, l))) return for i in range(start, N + 1): if not i in l: diff --git a/BOJ/Silver/15654/main.py b/BOJ/Silver/15654/main.py index 1b3c4f0..cf361a2 100644 --- a/BOJ/Silver/15654/main.py +++ b/BOJ/Silver/15654/main.py @@ -10,7 +10,7 @@ def DFS(): if len(l) == M: - print(' '.join(list(map(str, l)))) + print(" ".join(list(map(str, l)))) return else: for i in lst: diff --git a/BOJ/Silver/1654/main.py b/BOJ/Silver/1654/main.py index 6428c91..271239c 100644 --- a/BOJ/Silver/1654/main.py +++ b/BOJ/Silver/1654/main.py @@ -15,7 +15,7 @@ def countLan(l, length): M = max(l) ans = 0 -while (m <= M): +while m <= M: mid = int((m + M) / 2) if countLan(l, mid) >= N: m = mid + 1 diff --git a/BOJ/Silver/1676/main.py b/BOJ/Silver/1676/main.py index 69023aa..4ea385c 100644 --- a/BOJ/Silver/1676/main.py +++ b/BOJ/Silver/1676/main.py @@ -3,7 +3,7 @@ N = int(input()) cnt = 0 for x in str(math.factorial(N))[::-1]: - if x != '0': + if x != "0": break cnt += 1 print(cnt) diff --git a/BOJ/Silver/17478/main.py b/BOJ/Silver/17478/main.py index 81f841d..a56e466 100644 --- a/BOJ/Silver/17478/main.py +++ b/BOJ/Silver/17478/main.py @@ -4,19 +4,19 @@ def jaegui(tmp): if N > tmp: - print('____' * tmp + '"재귀함수가 뭔가요?"') - print('____' * tmp + '"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.') - print('____' * tmp + '마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.') - print('____' * tmp + '그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어."') + print("____" * tmp + '"재귀함수가 뭔가요?"') + print("____" * tmp + '"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.') + print("____" * tmp + "마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.") + print("____" * tmp + '그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어."') elif N == tmp: - print('____' * tmp + '"재귀함수가 뭔가요?"') - print('____' * tmp + '"재귀함수는 자기 자신을 호출하는 함수라네"') + print("____" * tmp + '"재귀함수가 뭔가요?"') + print("____" * tmp + '"재귀함수는 자기 자신을 호출하는 함수라네"') tmp += 1 if N >= tmp: jaegui(tmp) tmp -= 1 - print('____' * tmp + '라고 답변하였지.') + print("____" * tmp + "라고 답변하였지.") -print('어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.') +print("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.") jaegui(tmp) diff --git a/BOJ/Silver/18258/main.py b/BOJ/Silver/18258/main.py index 17205d5..3881af2 100644 --- a/BOJ/Silver/18258/main.py +++ b/BOJ/Silver/18258/main.py @@ -5,26 +5,26 @@ def comm(s): - if 'push' == s[0]: + if "push" == s[0]: q.append(int(s[1])) - elif 'pop' == s[0]: + elif "pop" == s[0]: try: print(q.popleft()) except BaseException: print(-1) - elif 'size' == s[0]: + elif "size" == s[0]: print(len(q)) - elif 'empty' == s[0]: + elif "empty" == s[0]: if len(q) == 0: print(1) else: print(0) - elif 'front' == s[0]: + elif "front" == s[0]: try: print(q[0]) except BaseException: print(-1) - elif 'back' == s[0]: + elif "back" == s[0]: try: print(q[-1]) except BaseException: diff --git a/BOJ/Silver/1874/main.py b/BOJ/Silver/1874/main.py index eb4b731..545e438 100644 --- a/BOJ/Silver/1874/main.py +++ b/BOJ/Silver/1874/main.py @@ -11,16 +11,16 @@ num = int(read()) while cnt <= num: st.append(cnt) - res.append('+') + res.append("+") cnt += 1 if st[-1] == num: st.pop() - res.append('-') + res.append("-") else: tmp = False if tmp == False: - print('NO') + print("NO") else: for i in res: print(i) diff --git a/BOJ/Silver/18870/main.py b/BOJ/Silver/18870/main.py index 406831a..c26f1af 100644 --- a/BOJ/Silver/18870/main.py +++ b/BOJ/Silver/18870/main.py @@ -7,7 +7,7 @@ l2 = [[l1[i], i] for i in range(N)] l2.sort(key=lambda x: x[0]) l3 = [0 for _ in range(N)] -tmp, reg = 0, -10**10 +tmp, reg = 0, -(10**10) for i in range(N): if i == 0: l3[l2[i][1]] = tmp @@ -18,4 +18,4 @@ tmp += 1 l3[l2[i][1]] = tmp for i in l3: - print(i, end=' ') + print(i, end=" ") diff --git a/BOJ/Silver/1929/main.py b/BOJ/Silver/1929/main.py index fa0b577..5f6cf6e 100644 --- a/BOJ/Silver/1929/main.py +++ b/BOJ/Silver/1929/main.py @@ -6,7 +6,7 @@ def returnPN(M, N): for i in range(M, N + 1): if i == 1: continue - for j in range(2, int(i ** 0.5) + 1): + for j in range(2, int(i**0.5) + 1): if i % j == 0: break else: diff --git a/BOJ/Silver/1978/Legacy/ver1.py b/BOJ/Silver/1978/Legacy/ver1.py index 967d639..52cdfde 100644 --- a/BOJ/Silver/1978/Legacy/ver1.py +++ b/BOJ/Silver/1978/Legacy/ver1.py @@ -1,6 +1,6 @@ def prime_list(n): sieve = [True] * n - m = int(n ** 0.5) + m = int(n**0.5) for i in range(2, m + 1): if sieve[i] == True: for j in range(i + i, n, i): diff --git a/BOJ/Silver/1991/main.py b/BOJ/Silver/1991/main.py index b743a14..274d51f 100644 --- a/BOJ/Silver/1991/main.py +++ b/BOJ/Silver/1991/main.py @@ -10,28 +10,28 @@ def preorder(root): - if root != '.': - print(root, end='') + if root != ".": + print(root, end="") preorder(tree[root][0]) preorder(tree[root][1]) def inorder(root): - if root != '.': + if root != ".": inorder(tree[root][0]) - print(root, end='') + print(root, end="") inorder(tree[root][1]) def postorder(root): - if root != '.': + if root != ".": postorder(tree[root][0]) postorder(tree[root][1]) - print(root, end='') + print(root, end="") -preorder('A') +preorder("A") print() -inorder('A') +inorder("A") print() -postorder('A') +postorder("A") diff --git a/BOJ/Silver/2164/main.py b/BOJ/Silver/2164/main.py index a1edc37..d029376 100644 --- a/BOJ/Silver/2164/main.py +++ b/BOJ/Silver/2164/main.py @@ -2,10 +2,10 @@ square = 2 while True: - if (input == 1 or input == 2): + if input == 1 or input == 2: print(input) break square *= 2 - if (square >= input): + if square >= input: print((input - (square // 2)) * 2) break diff --git a/BOJ/Silver/25178/main.py b/BOJ/Silver/25178/main.py index 52440ae..e875342 100644 --- a/BOJ/Silver/25178/main.py +++ b/BOJ/Silver/25178/main.py @@ -6,18 +6,18 @@ N = int(read()) A = str(read().rstrip()) B = str(read().rstrip()) -moum = ('a', 'e', 'i', 'o', 'u') +moum = ("a", "e", "i", "o", "u") cA = Counter(A) cB = Counter(B) if cA == cB and A[0] == B[0] and A[-1] == B[-1]: for i in moum: - A = A.replace(i, '') - B = B.replace(i, '') + A = A.replace(i, "") + B = B.replace(i, "") if A == B: - print('YES') + print("YES") else: - print('NO') + print("NO") else: - print('NO') + print("NO") diff --git a/BOJ/Silver/2583/main.py b/BOJ/Silver/2583/main.py index ed05a92..ee4cdc4 100644 --- a/BOJ/Silver/2583/main.py +++ b/BOJ/Silver/2583/main.py @@ -45,6 +45,6 @@ def draw(x1, y1, x2, y2): print(cnt) for i in res: if i == 0: - print(1, end=' ') + print(1, end=" ") else: - print(i, end=' ') + print(i, end=" ") diff --git a/BOJ/Silver/4949/main.py b/BOJ/Silver/4949/main.py index 14a85c9..4fd73be 100644 --- a/BOJ/Silver/4949/main.py +++ b/BOJ/Silver/4949/main.py @@ -5,21 +5,21 @@ s = [] tmp = True for i in str: - if i == '(' or i == '[': + if i == "(" or i == "[": s.append(i) - elif i == ')': - if not s or s[-1] == '[': + elif i == ")": + if not s or s[-1] == "[": tmp = False break - elif s[-1] == '(': + elif s[-1] == "(": s.pop() - elif i == ']': - if not s or s[-1] == '(': + elif i == "]": + if not s or s[-1] == "(": tmp = False break - elif s[-1] == '[': + elif s[-1] == "[": s.pop() if tmp == True and not s: - print('yes') + print("yes") else: - print('no') + print("no") diff --git a/BOJ/Silver/7568/main.py b/BOJ/Silver/7568/main.py index a209a49..a6a1802 100644 --- a/BOJ/Silver/7568/main.py +++ b/BOJ/Silver/7568/main.py @@ -16,4 +16,4 @@ res.append(cnt + 1) for i in res: - print(i, end=' ') + print(i, end=" ") diff --git a/BOJ/Silver/9012/main.py b/BOJ/Silver/9012/main.py index f549b06..980c76f 100644 --- a/BOJ/Silver/9012/main.py +++ b/BOJ/Silver/9012/main.py @@ -3,13 +3,13 @@ S = input() tmp = 0 for i in range(len(S)): - if S[i] == '(': + if S[i] == "(": tmp += 1 - elif S[i] == ')': + elif S[i] == ")": tmp -= 1 if tmp < 0: tmp = -100 if tmp == 0: - print('YES') + print("YES") else: - print('NO') + print("NO") diff --git a/BOJ/Silver/9655/main.py b/BOJ/Silver/9655/main.py index 05cbf5c..52a6fe0 100644 --- a/BOJ/Silver/9655/main.py +++ b/BOJ/Silver/9655/main.py @@ -3,6 +3,6 @@ N = int(sys.stdin.readline()) if N % 2 != 0: - print('SK') + print("SK") else: - print('CY') + print("CY") diff --git a/CodeUp/6095/main.py b/CodeUp/6095/main.py index eb4a223..a1c6db0 100644 --- a/CodeUp/6095/main.py +++ b/CodeUp/6095/main.py @@ -14,5 +14,5 @@ for i in range(19): for j in range(19): - print(d[i][j], end=' ') + print(d[i][j], end=" ") print() diff --git a/CodeUp/6096/main.py b/CodeUp/6096/main.py index c8ce956..eaedb60 100644 --- a/CodeUp/6096/main.py +++ b/CodeUp/6096/main.py @@ -12,19 +12,19 @@ for i in x: for j in range(19): - if d[i][j] == '1': - d[i][j] = '0' + if d[i][j] == "1": + d[i][j] = "0" else: - d[i][j] = '1' + d[i][j] = "1" for i in y: for j in range(19): - if d[j][i] == '1': - d[j][i] = '0' + if d[j][i] == "1": + d[j][i] = "0" else: - d[j][i] = '1' + d[j][i] = "1" for i in range(19): for j in range(19): - print(d[i][j], end=' ') + print(d[i][j], end=" ") print() diff --git a/CodeUp/6097/main.py b/CodeUp/6097/main.py index c7f1734..81097ae 100644 --- a/CodeUp/6097/main.py +++ b/CodeUp/6097/main.py @@ -1,10 +1,10 @@ def convertMatrix(stickInfo, matrix): - if stickInfo[1] == '0': + if stickInfo[1] == "0": for i in range(int(stickInfo[0])): - matrix[int(stickInfo[2]) - 1][int(stickInfo[3]) - 1 + i] = '1' - elif stickInfo[1] == '1': + matrix[int(stickInfo[2]) - 1][int(stickInfo[3]) - 1 + i] = "1" + elif stickInfo[1] == "1": for i in range(int(stickInfo[0])): - matrix[int(stickInfo[2]) - 1 + i][int(stickInfo[3]) - 1] = '1' + matrix[int(stickInfo[2]) - 1 + i][int(stickInfo[3]) - 1] = "1" return matrix @@ -20,5 +20,5 @@ def convertMatrix(stickInfo, matrix): d = convertMatrix(sticks[:][i], d) for i in range(a): for j in range(b): - print(d[i][j], end=' ') + print(d[i][j], end=" ") print() diff --git a/CodeUp/6098/main.py b/CodeUp/6098/main.py index fa3e806..1064fea 100644 --- a/CodeUp/6098/main.py +++ b/CodeUp/6098/main.py @@ -4,16 +4,16 @@ hungry = 1 tmp = [1, 1] while hungry > 0: - if d[tmp[0]][tmp[1]] == '2': + if d[tmp[0]][tmp[1]] == "2": hungry = hungry - 1 - d[tmp[0]][tmp[1]] = '9' - if d[tmp[0]][tmp[1] + 1] != '1': + d[tmp[0]][tmp[1]] = "9" + if d[tmp[0]][tmp[1] + 1] != "1": tmp[1] = tmp[1] + 1 - elif d[tmp[0] + 1][tmp[1]] != '1': + elif d[tmp[0] + 1][tmp[1]] != "1": tmp[0] = tmp[0] + 1 else: hungry = 0 for i in range(10): for j in range(10): - print(d[i][j], end=' ') + print(d[i][j], end=" ") print() diff --git a/Codility/Exercises/2015_Contest/LongestPassword/README.md b/Codility/Exercises/2015_Contest/LongestPassword/README.md index 87686f0..5e580d9 100644 --- a/Codility/Exercises/2015_Contest/LongestPassword/README.md +++ b/Codility/Exercises/2015_Contest/LongestPassword/README.md @@ -1 +1 @@ -[Solution](https://app.codility.com/demo/results/trainingT5WCRR-TAW/) \ No newline at end of file +[Solution](https://app.codility.com/demo/results/trainingT5WCRR-TAW/) diff --git a/Codility/Exercises/2015_Contest/LongestPassword/main.py b/Codility/Exercises/2015_Contest/LongestPassword/main.py index 6352cc3..a4e5a9b 100644 --- a/Codility/Exercises/2015_Contest/LongestPassword/main.py +++ b/Codility/Exercises/2015_Contest/LongestPassword/main.py @@ -1,6 +1,7 @@ # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") + def solution(S): # write your code in Python 3.8.10 words = S.split() diff --git a/Codility/Exercises/Algorithmic_skills/FirstUnique/README.md b/Codility/Exercises/Algorithmic_skills/FirstUnique/README.md index 4055583..950ab92 100644 --- a/Codility/Exercises/Algorithmic_skills/FirstUnique/README.md +++ b/Codility/Exercises/Algorithmic_skills/FirstUnique/README.md @@ -2,4 +2,4 @@ *** -[Legacy_1](https://app.codility.com/demo/results/trainingM4AJ4H-68D/) \ No newline at end of file +[Legacy_1](https://app.codility.com/demo/results/trainingM4AJ4H-68D/) diff --git a/Codility/Exercises/Algorithmic_skills/StrSymmetryPoint/README.md b/Codility/Exercises/Algorithmic_skills/StrSymmetryPoint/README.md index ce46926..bb91df6 100644 --- a/Codility/Exercises/Algorithmic_skills/StrSymmetryPoint/README.md +++ b/Codility/Exercises/Algorithmic_skills/StrSymmetryPoint/README.md @@ -1 +1 @@ -[Solution](https://app.codility.com/demo/results/trainingPM6FE3-G57/) \ No newline at end of file +[Solution](https://app.codility.com/demo/results/trainingPM6FE3-G57/) diff --git a/Codility/Exercises/Algorithmic_skills/StrSymmetryPoint/main.py b/Codility/Exercises/Algorithmic_skills/StrSymmetryPoint/main.py index 7b8f5f5..3015cbe 100644 --- a/Codility/Exercises/Algorithmic_skills/StrSymmetryPoint/main.py +++ b/Codility/Exercises/Algorithmic_skills/StrSymmetryPoint/main.py @@ -1,6 +1,7 @@ # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") + def solution(S): # write your code in Python 3.8.10 N = len(S) diff --git a/Codility/Exercises/Algorithmic_skills/TreeHeight/README.md b/Codility/Exercises/Algorithmic_skills/TreeHeight/README.md index 4f0d5bb..e21c474 100644 --- a/Codility/Exercises/Algorithmic_skills/TreeHeight/README.md +++ b/Codility/Exercises/Algorithmic_skills/TreeHeight/README.md @@ -1 +1 @@ -[Solution](https://app.codility.com/demo/results/trainingQ6P53T-32Q/) \ No newline at end of file +[Solution](https://app.codility.com/demo/results/trainingQ6P53T-32Q/) diff --git a/Functions/SegmentTree.py b/Functions/SegmentTree.py index ef7a7b4..b820384 100644 --- a/Functions/SegmentTree.py +++ b/Functions/SegmentTree.py @@ -3,8 +3,9 @@ def init(node, start, end): tree[node] = l[start] return tree[node] else: - tree[node] = init(node * 2, start, (start + end) // 2) + \ - init(node * 2 + 1, (start + end) // 2 + 1, end) + tree[node] = init(node * 2, start, (start + end) // 2) + init( + node * 2 + 1, (start + end) // 2 + 1, end + ) return tree[node] @@ -22,5 +23,6 @@ def segSum(node, start, end, left, right): return 0 if left <= start and end <= right: return tree[node] - return segSum(node * 2, start, (start + end) // 2, left, right) + \ - segSum(node * 2 + 1, (start + end) // 2 + 1, end, left, right) + return segSum(node * 2, start, (start + end) // 2, left, right) + segSum( + node * 2 + 1, (start + end) // 2 + 1, end, left, right + ) diff --git a/Functions/fft.py b/Functions/fft.py index 46a2092..78bbdad 100644 --- a/Functions/fft.py +++ b/Functions/fft.py @@ -9,11 +9,13 @@ def fft(sig, inv): sig_even = fft(sig[0::2], 0) sig_odd = fft(sig[1::2], 0) W = [exp(2j * pi * i / N) for i in range(N // 2)] - return [sig_even[i] + W[i] * sig_odd[i] - for i in range(N // 2)] + [sig_even[i] - W[i] * sig_odd[i] for i in range(N // 2)] + return [sig_even[i] + W[i] * sig_odd[i] for i in range(N // 2)] + [ + sig_even[i] - W[i] * sig_odd[i] for i in range(N // 2) + ] elif inv == 1: sig_even = fft(sig[0::2], 1) sig_odd = fft(sig[1::2], 1) W = [exp(-2j * pi * i / N) for i in range(N // 2)] - return [sig_even[i] + W[i] * sig_odd[i] - for i in range(N // 2)] + [sig_even[i] - W[i] * sig_odd[i] for i in range(N // 2)] + return [sig_even[i] + W[i] * sig_odd[i] for i in range(N // 2)] + [ + sig_even[i] - W[i] * sig_odd[i] for i in range(N // 2) + ] diff --git a/Functions/returnPN.py b/Functions/returnPN.py index ca2e058..05747d5 100644 --- a/Functions/returnPN.py +++ b/Functions/returnPN.py @@ -3,7 +3,7 @@ def returnPN(M, N): for i in range(M, N + 1): if i == 1: continue - for j in range(2, int(i ** 0.5) + 1): + for j in range(2, int(i**0.5) + 1): if i % j == 0: break else: diff --git "a/Programmers/2020_KAKAO_BLIND_RECRUITMENT/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240/main.py" "b/Programmers/2020_KAKAO_BLIND_RECRUITMENT/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240/main.py" index 64741a8..6216bc9 100644 --- "a/Programmers/2020_KAKAO_BLIND_RECRUITMENT/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240/main.py" +++ "b/Programmers/2020_KAKAO_BLIND_RECRUITMENT/\354\236\220\353\254\274\354\207\240\354\231\200_\354\227\264\354\207\240/main.py" @@ -13,12 +13,12 @@ def convert_func(rot, s1, s2, idx_i_1, idx_j_1, idx_i_2, idx_j_2, i, j): return ni, nj -def match(rot, key, M, lock, N, s1, s2, idx_i, - idx_j, idx_i_1, idx_j_1, idx_i_2, idx_j_2): +def match( + rot, key, M, lock, N, s1, s2, idx_i, idx_j, idx_i_1, idx_j_1, idx_i_2, idx_j_2 +): for i in range(M): for j in range(M): - ni, nj = convert_func( - rot, s1, s2, idx_i_1, idx_j_1, idx_i_2, idx_j_2, i, j) + ni, nj = convert_func(rot, s1, s2, idx_i_1, idx_j_1, idx_i_2, idx_j_2, i, j) if (0 <= ni < N) and (0 <= nj < N): if (idx_i_1 <= ni <= idx_i_2) and (idx_j_1 <= nj <= idx_j_2): if key[i][j] == lock[ni][nj]: @@ -36,7 +36,6 @@ def match(rot, key, M, lock, N, s1, s2, idx_i, def solution(key, lock): - keyRange = [[], []] N, M = len(lock), len(key) idx_i_1, idx_j_1, idx_i_2, idx_j_2 = sys.maxsize, sys.maxsize, 0, 0 for i in range(N): @@ -54,7 +53,20 @@ def solution(key, lock): for rot in range(4): for s1 in range(M - idx_i): for s2 in range(M - idx_j): - if match(rot, key, M, lock, N, s1, s2, idx_i, - idx_j, idx_i_1, idx_j_1, idx_i_2, idx_j_2): + if match( + rot, + key, + M, + lock, + N, + s1, + s2, + idx_i, + idx_j, + idx_i_1, + idx_j_1, + idx_i_2, + idx_j_2, + ): return True return False diff --git "a/Programmers/2021_KAKAO_BLIND_RECRUITMENT/\353\251\224\353\211\264_\353\246\254\353\211\264\354\226\274/main.py" "b/Programmers/2021_KAKAO_BLIND_RECRUITMENT/\353\251\224\353\211\264_\353\246\254\353\211\264\354\226\274/main.py" index a5a284d..87ebdc6 100644 --- "a/Programmers/2021_KAKAO_BLIND_RECRUITMENT/\353\251\224\353\211\264_\353\246\254\353\211\264\354\226\274/main.py" +++ "b/Programmers/2021_KAKAO_BLIND_RECRUITMENT/\353\251\224\353\211\264_\353\246\254\353\211\264\354\226\274/main.py" @@ -7,7 +7,7 @@ def solution(orders, course): ord = {} for order in orders: for tmporder in combinations(sorted(order), c): - tmp = ''.join(tmporder) + tmp = "".join(tmporder) if tmp in ord: ord[tmp] += 1 else: diff --git "a/Programmers/Brute_Force/\353\252\250\354\235\214\354\202\254\354\240\204/main.py" "b/Programmers/Brute_Force/\353\252\250\354\235\214\354\202\254\354\240\204/main.py" index 0a091f3..1d733b6 100644 --- "a/Programmers/Brute_Force/\353\252\250\354\235\214\354\202\254\354\240\204/main.py" +++ "b/Programmers/Brute_Force/\353\252\250\354\235\214\354\202\254\354\240\204/main.py" @@ -2,10 +2,10 @@ def solution(word): - char = ['A', 'E', 'I', 'O', 'U'] + char = ["A", "E", "I", "O", "U"] tmp = [] for i in range(1, 6): for j in product(char, repeat=i): - tmp.append(''.join(list(j))) + tmp.append("".join(list(j))) tmp.sort() return tmp.index(word) + 1 diff --git "a/Programmers/Brute_Force/\354\206\214\354\210\230_\354\260\276\352\270\260/main.py" "b/Programmers/Brute_Force/\354\206\214\354\210\230_\354\260\276\352\270\260/main.py" index d7ac466..14ec788 100644 --- "a/Programmers/Brute_Force/\354\206\214\354\210\230_\354\260\276\352\270\260/main.py" +++ "b/Programmers/Brute_Force/\354\206\214\354\210\230_\354\260\276\352\270\260/main.py" @@ -4,7 +4,7 @@ def cPN(n): if n < 2: return False - for i in range(2, int(n ** 0.5) + 1): + for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True @@ -16,7 +16,7 @@ def solution(numbers): numbers = list(numbers) for i in range(1, len(numbers) + 1): tmp += permutations(numbers, i) - num = [int(''.join(t)) for t in tmp] + num = [int("".join(t)) for t in tmp] for i in num: if cPN(i): answer.append(i) diff --git "a/Programmers/DFS_and_BFS/\352\262\214\354\236\204_\353\247\265_\354\265\234\353\213\250\352\261\260\353\246\254/Legacy/ver1_DFS.py" "b/Programmers/DFS_and_BFS/\352\262\214\354\236\204_\353\247\265_\354\265\234\353\213\250\352\261\260\353\246\254/Legacy/ver1_DFS.py" index 4239d5f..6130299 100644 --- "a/Programmers/DFS_and_BFS/\352\262\214\354\236\204_\353\247\265_\354\265\234\353\213\250\352\261\260\353\246\254/Legacy/ver1_DFS.py" +++ "b/Programmers/DFS_and_BFS/\352\262\214\354\236\204_\353\247\265_\354\265\234\353\213\250\352\261\260\353\246\254/Legacy/ver1_DFS.py" @@ -7,8 +7,12 @@ def DFS(maps, pos, cnt): return maps else: for i, j in zip(v1, v2): - if pos[0] + i > -1 and pos[1] + j > - \ - 1 and pos[0] + i < N and pos[1] + j < M: + if ( + pos[0] + i > -1 + and pos[1] + j > -1 + and pos[0] + i < N + and pos[1] + j < M + ): if maps[pos[0] + i][pos[1] + j] == 1: cnt += 1 maps[pos[0] + i][pos[1] + j] = cnt diff --git "a/Programmers/DFS_and_BFS/\352\262\214\354\236\204_\353\247\265_\354\265\234\353\213\250\352\261\260\353\246\254/main.py" "b/Programmers/DFS_and_BFS/\352\262\214\354\236\204_\353\247\265_\354\265\234\353\213\250\352\261\260\353\246\254/main.py" index 995880c..ed7f370 100644 --- "a/Programmers/DFS_and_BFS/\352\262\214\354\236\204_\353\247\265_\354\265\234\353\213\250\352\261\260\353\246\254/main.py" +++ "b/Programmers/DFS_and_BFS/\352\262\214\354\236\204_\353\247\265_\354\265\234\353\213\250\352\261\260\353\246\254/main.py" @@ -11,8 +11,12 @@ def BFS(maps): while q: tmp = q.popleft() for i, j in zip(v1, v2): - if tmp[0] + i > -1 and tmp[1] + j > - \ - 1 and tmp[0] + i < N and tmp[1] + j < M: + if ( + tmp[0] + i > -1 + and tmp[1] + j > -1 + and tmp[0] + i < N + and tmp[1] + j < M + ): if maps[tmp[0] + i][tmp[1] + j] == 1: q.append([tmp[0] + i, tmp[1] + j]) maps[tmp[0] + i][tmp[1] + j] = maps[tmp[0]][tmp[1]] + 1 diff --git "a/Programmers/DFS_and_BFS/\355\203\200\352\262\237_\353\204\230\353\262\204/main.py" "b/Programmers/DFS_and_BFS/\355\203\200\352\262\237_\353\204\230\353\262\204/main.py" index 36940a7..2b2a0c6 100644 --- "a/Programmers/DFS_and_BFS/\355\203\200\352\262\237_\353\204\230\353\262\204/main.py" +++ "b/Programmers/DFS_and_BFS/\355\203\200\352\262\237_\353\204\230\353\262\204/main.py" @@ -11,5 +11,6 @@ def DFS(idx, result): else: DFS(idx + 1, result + numbers[idx]) DFS(idx + 1, result - numbers[idx]) + DFS(0, 0) return answer diff --git "a/Programmers/Greedy/\354\241\260\354\235\264\354\212\244\355\213\261/main.py" "b/Programmers/Greedy/\354\241\260\354\235\264\354\212\244\355\213\261/main.py" index 3c51a82..ce76058 100644 --- "a/Programmers/Greedy/\354\241\260\354\235\264\354\212\244\355\213\261/main.py" +++ "b/Programmers/Greedy/\354\241\260\354\235\264\354\212\244\355\213\261/main.py" @@ -2,9 +2,9 @@ def solution(name): answer = 0 mmove = len(name) - 1 for i, c in enumerate(name): - answer += min(ord(c) - ord('A'), ord('Z') - ord(c) + 1) + answer += min(ord(c) - ord("A"), ord("Z") - ord(c) + 1) n = i + 1 - while n < len(name) and name[n] == 'A': + while n < len(name) and name[n] == "A": n += 1 mmove = min([mmove, 2 * i + len(name) - n, i + 2 * (len(name) - n)]) answer += mmove diff --git "a/Programmers/Greedy/\355\201\260_\354\210\230_\353\247\214\353\223\244\352\270\260/main.py" "b/Programmers/Greedy/\355\201\260_\354\210\230_\353\247\214\353\223\244\352\270\260/main.py" index fbe7d20..6870cf2 100644 --- "a/Programmers/Greedy/\355\201\260_\354\210\230_\353\247\214\353\223\244\352\270\260/main.py" +++ "b/Programmers/Greedy/\355\201\260_\354\210\230_\353\247\214\353\223\244\352\270\260/main.py" @@ -5,5 +5,5 @@ def solution(number, k): answer.pop() k -= 1 answer.append(n) - answer = ''.join(answer[:len(number) - k]) + answer = "".join(answer[: len(number) - k]) return answer diff --git "a/Programmers/Hash/\354\240\204\355\231\224\353\262\210\355\230\270_\353\252\251\353\241\235/main.py" "b/Programmers/Hash/\354\240\204\355\231\224\353\262\210\355\230\270_\353\252\251\353\241\235/main.py" index ab71446..46d893d 100644 --- "a/Programmers/Hash/\354\240\204\355\231\224\353\262\210\355\230\270_\353\252\251\353\241\235/main.py" +++ "b/Programmers/Hash/\354\240\204\355\231\224\353\262\210\355\230\270_\353\252\251\353\241\235/main.py" @@ -2,7 +2,7 @@ def solution(phone_book): answer = True phone_book.sort() for i in range(len(phone_book) - 1): - if phone_book[i] == phone_book[i + 1][:len(phone_book[i])]: + if phone_book[i] == phone_book[i + 1][: len(phone_book[i])]: answer = False break return answer diff --git "a/Programmers/Heap/\353\224\224\354\212\244\355\201\254_\354\273\250\355\212\270\353\241\244\353\237\254/main.py" "b/Programmers/Heap/\353\224\224\354\212\244\355\201\254_\354\273\250\355\212\270\353\241\244\353\237\254/main.py" index ef90a4b..a465920 100644 --- "a/Programmers/Heap/\353\224\224\354\212\244\355\201\254_\354\273\250\355\212\270\353\241\244\353\237\254/main.py" +++ "b/Programmers/Heap/\353\224\224\354\212\244\355\201\254_\354\273\250\355\212\270\353\241\244\353\237\254/main.py" @@ -14,7 +14,7 @@ def solution(jobs): tmp = heapq.heappop(h) start = end end += tmp[0] - answer += (end - tmp[1]) + answer += end - tmp[1] i += 1 else: end += 1 diff --git "a/Programmers/Heap/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/main.py" "b/Programmers/Heap/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/main.py" index cdd9c16..9414acf 100644 --- "a/Programmers/Heap/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/main.py" +++ "b/Programmers/Heap/\354\235\264\354\244\221\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/main.py" @@ -6,16 +6,16 @@ def solution(operations): Mheap = [] for oper in operations: tmpoper = oper.split() - if tmpoper[0] == 'I': + if tmpoper[0] == "I": heapq.heappush(mheap, int(tmpoper[1])) heapq.heappush(Mheap, ((-int(tmpoper[1])), int(tmpoper[1]))) - elif tmpoper[0] == 'D': + elif tmpoper[0] == "D": if not mheap: pass - elif tmpoper[1] == '1': + elif tmpoper[1] == "1": tmp = heapq.heappop(Mheap) mheap.remove(tmp[1]) - elif tmpoper[1] == '-1': + elif tmpoper[1] == "-1": tmp = heapq.heappop(mheap) Mheap.remove((-tmp, tmp)) if mheap: diff --git a/Programmers/Sort/H-Index/main.py b/Programmers/Sort/H-Index/main.py index 0b9c42c..f1f33a8 100644 --- a/Programmers/Sort/H-Index/main.py +++ b/Programmers/Sort/H-Index/main.py @@ -1,5 +1,4 @@ def solution(citations): - answer = 0 citations.sort(reverse=True) for i, citation in enumerate(citations): if i >= citation: diff --git "a/Programmers/Sort/K\353\262\210\354\247\270\354\210\230/main.py" "b/Programmers/Sort/K\353\262\210\354\247\270\354\210\230/main.py" index 20d0936..31df063 100644 --- "a/Programmers/Sort/K\353\262\210\354\247\270\354\210\230/main.py" +++ "b/Programmers/Sort/K\353\262\210\354\247\270\354\210\230/main.py" @@ -1,6 +1,6 @@ def solution(array, commands): answer = [] for command in commands: - tmparr = sorted(array[command[0] - 1:command[1]]) + tmparr = sorted(array[command[0] - 1 : command[1]]) answer.append(tmparr[command[2] - 1]) return answer diff --git "a/Programmers/Sort/\352\260\200\354\236\245_\355\201\260_\354\210\230/main.py" "b/Programmers/Sort/\352\260\200\354\236\245_\355\201\260_\354\210\230/main.py" index 30690bc..c625fbd 100644 --- "a/Programmers/Sort/\352\260\200\354\236\245_\355\201\260_\354\210\230/main.py" +++ "b/Programmers/Sort/\352\260\200\354\236\245_\355\201\260_\354\210\230/main.py" @@ -1,5 +1,4 @@ def solution(numbers): - answer = '' numarr = list(map(str, numbers)) numarr.sort(key=lambda x: x * 3, reverse=True) - return str(int(''.join(numarr))) + return str(int("".join(numarr))) diff --git "a/Programmers/Stack_and_Queue/\354\230\254\353\260\224\353\245\270_\352\264\204\355\230\270/main.py" "b/Programmers/Stack_and_Queue/\354\230\254\353\260\224\353\245\270_\352\264\204\355\230\270/main.py" index 27d5ba4..520039e 100644 --- "a/Programmers/Stack_and_Queue/\354\230\254\353\260\224\353\245\270_\352\264\204\355\230\270/main.py" +++ "b/Programmers/Stack_and_Queue/\354\230\254\353\260\224\353\245\270_\352\264\204\355\230\270/main.py" @@ -1,9 +1,9 @@ def solution(s): tmp = 0 for i in list(s): - if i == '(': + if i == "(": tmp += 1 - elif i == ')': + elif i == ")": tmp -= 1 if tmp < 0: return False diff --git "a/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/JadenCase_\353\254\270\354\236\220\354\227\264_\353\247\214\353\223\244\352\270\260/Legacy/ver1.py" "b/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/JadenCase_\353\254\270\354\236\220\354\227\264_\353\247\214\353\223\244\352\270\260/Legacy/ver1.py" index 45bafc1..e9caf45 100644 --- "a/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/JadenCase_\353\254\270\354\236\220\354\227\264_\353\247\214\353\223\244\352\270\260/Legacy/ver1.py" +++ "b/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/JadenCase_\353\254\270\354\236\220\354\227\264_\353\247\214\353\223\244\352\270\260/Legacy/ver1.py" @@ -1,7 +1,7 @@ def solution(s): - answer = '' - l = s.split(' ') - answer = '' + answer = "" + l = s.split(" ") + answer = "" for i in l: tmp = 0 for j in i: @@ -17,6 +17,6 @@ def solution(s): answer += chr(ord(j) + 32) else: answer += j - answer += ' ' + answer += " " answer = answer.strip() return answer diff --git "a/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/JadenCase_\353\254\270\354\236\220\354\227\264_\353\247\214\353\223\244\352\270\260/main.py" "b/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/JadenCase_\353\254\270\354\236\220\354\227\264_\353\247\214\353\223\244\352\270\260/main.py" index 23a12f1..1a26b29 100644 --- "a/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/JadenCase_\353\254\270\354\236\220\354\227\264_\353\247\214\353\223\244\352\270\260/main.py" +++ "b/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/JadenCase_\353\254\270\354\236\220\354\227\264_\353\247\214\353\223\244\352\270\260/main.py" @@ -1,8 +1,8 @@ def solution(s): - answer = '' - l = s.split(' ') - answer = '' + answer = "" + l = s.split(" ") + answer = "" for i in range(len(l)): l[i] = l[i].capitalize() - answer = ' '.join(l) + answer = " ".join(l) return answer diff --git "a/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/\353\213\244\354\235\214_\355\201\260_\354\210\253\354\236\220/main.py" "b/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/\353\213\244\354\235\214_\355\201\260_\354\210\253\354\236\220/main.py" index 1a1e12a..f468e35 100644 --- "a/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/\353\213\244\354\235\214_\355\201\260_\354\210\253\354\236\220/main.py" +++ "b/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/\353\213\244\354\235\214_\355\201\260_\354\210\253\354\236\220/main.py" @@ -1,8 +1,8 @@ def solution(n): tmp = n + 1 - b = bin(n).count('1') + b = bin(n).count("1") while True: - if bin(tmp).count('1') == b: + if bin(tmp).count("1") == b: break tmp += 1 return tmp diff --git "a/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/\354\265\234\353\214\223\352\260\222\352\263\274_\354\265\234\354\206\237\352\260\222/main.py" "b/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/\354\265\234\353\214\223\352\260\222\352\263\274_\354\265\234\354\206\237\352\260\222/main.py" index eb848fd..ce1f733 100644 --- "a/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/\354\265\234\353\214\223\352\260\222\352\263\274_\354\265\234\354\206\237\352\260\222/main.py" +++ "b/Programmers/\354\227\260\354\212\265\353\254\270\354\240\234/\354\265\234\353\214\223\352\260\222\352\263\274_\354\265\234\354\206\237\352\260\222/main.py" @@ -1,4 +1,4 @@ def solution(s): l = list(map(int, s.split())) - answer = str(min(l)) + ' ' + str(max(l)) + answer = str(min(l)) + " " + str(max(l)) return answer diff --git a/README.md b/README.md index d9650f2..6550ff3 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,4 @@ Solved problems in ... -

\ No newline at end of file +