Skip to content

Commit 7e780e6

Browse files
authored
Merge pull request #797 from DosImpact/master
소수찾기
2 parents 723fe22 + 91cbe27 commit 7e780e6

File tree

9 files changed

+174
-103
lines changed

9 files changed

+174
-103
lines changed

BOJ/1261.알고스팟/dosimpact.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
import math
3+
from typing import *
4+
import itertools
5+
from collections import deque
6+
7+
8+
# 알고스팟
9+
# N,M 빈방 - 가중치 0, 벽 1
10+
11+
M, N = map(int, input().split())
12+
graph: List[List[int]] = [list(map(int, list(input()))) for _ in range(N)]
13+
check: List[List[int]] = [[-1 for _ in range(M)] for _ in range(N)]
14+
15+
16+
def inRange(x: int, y: int):
17+
return x >= 0 and y >= 0 and x < N and y < M
18+
19+
20+
dx, dy = [0, 0, 1, -1], [1, -1, 0, 0]
21+
q = deque()
22+
q.append((0, 0)) # 0,0 으로 들어옴
23+
check[0][0] = 0
24+
25+
while q:
26+
x, y = q.popleft()
27+
for k in range(4):
28+
nx, ny = x+dx[k], y+dy[k]
29+
if inRange(nx, ny) and check[nx][ny] == -1:
30+
if graph[nx][ny] == 0:
31+
check[nx][ny] = check[x][y]
32+
q.appendleft((nx, ny))
33+
continue
34+
if graph[nx][ny] == 1:
35+
check[nx][ny] = check[x][y] + 1
36+
q.append((nx, ny))
37+
continue
38+
39+
print(check[N-1][M-1])
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import sys
2+
3+
sys.setrecursionlimit(10**6)
4+
input = sys.stdin.readline
5+
6+
T = int(input())
7+
8+
for _ in range(T):
9+
F = int(input())
10+
names = dict()
11+
names_cnt = 0
12+
# 이름 > 번호로 변경
13+
parent = [i for i in range(F*2+1)]
14+
childNum = [1 for i in range(F*2+1)]
15+
16+
def getNumber(name: str):
17+
global names_cnt
18+
if name in names:
19+
return names[name]
20+
else:
21+
names[name] = names_cnt
22+
names_cnt += 1
23+
return names[name]
24+
25+
def getP(x: int):
26+
if parent[x] == x:
27+
return x
28+
parent[x] = getP(parent[x])
29+
return parent[x]
30+
31+
def union(x: int, y: int):
32+
px, py = getP(x), getP(y)
33+
if px == py:
34+
return
35+
if px > py:
36+
parent[px] = py
37+
childNum[py] += childNum[px]
38+
else:
39+
parent[py] = px
40+
childNum[px] += childNum[py]
41+
42+
for _ in range(F):
43+
u, v = input().strip().split()
44+
un, vn = getNumber(u), getNumber(v)
45+
union(un, vn)
46+
pn = getP(un)
47+
print(childNum[pn])
48+
# print(f"childNum : {childNum} u,v ={u} {v} , un vn = {un} {vn} ")
49+
50+
"""
51+
1
52+
6
53+
Fred Barney
54+
Betty Wilma
55+
Barney Betty
56+
Fred Barney
57+
Barney Betty
58+
Betty Wilma
59+
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 토스 체
2+
3+
4+
def solution(n: int):
5+
# check -1 이면 검사 안한것
6+
check = [-1 for i in range(0, n + 1)]
7+
pc = 0 # prime count
8+
pn = [] # prime array
9+
10+
# 2,3,....n
11+
for i in range(2, n + 1):
12+
if check[i] == -1:
13+
pc += 1
14+
pn.append(i)
15+
# 5*5 =25 , 30, 35 ,... n
16+
for j in range(i * i, n + 1, i):
17+
check[j] = 1
18+
# print(f"Primse is {pn}")
19+
return pc
20+
21+
22+
print(solution(10))
23+
print(solution(5))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import sys
2+
import math
3+
from typing import *
4+
5+
sys.setrecursionlimit(10**6)
6+
input = sys.stdin.readline
7+
8+
# 규칙에 맞지 않는 아이디를 입력했을 때 아이디와 유사하면서 규칙에 맞는 아이디를 추천해주는
9+
10+
11+
# 아이디의 길이는 3자 이상 15자 이하여야 합니다.
12+
# 알파벳 소문자, 숫자, 빼기(-), 밑줄(_), 마침표(.) 문자만 사용
13+
# 단, 마침표(.)는 처음과 끝에 사용할 수 없으며 또한 연속으로 사용할 수 없습
14+
15+
16+
def solution(new_id: str):
17+
new_id = list(new_id)
18+
new_id = list(map(lambda x: (x).lower() if (x).isupper() else x, new_id))
19+
print(new_id) # 1
20+
21+
def ST2(ch: str):
22+
if ch.isalnum() or ch == '-' or ch == '_' or ch == '.':
23+
return True
24+
return False
25+
new_id = list(filter(ST2, new_id))
26+
print(new_id) # 2
27+
28+
new_id_parsed = [new_id[0]]
29+
for i in range(1, len(new_id)):
30+
if new_id_parsed[-1] == '.' and new_id[i] == '.':
31+
continue
32+
new_id_parsed += [new_id[i]]
33+
new_id = new_id_parsed
34+
35+
print(new_id) # 3
36+
if new_id and new_id[0] == '.':
37+
new_id.pop(0)
38+
if new_id and new_id[-1] == '.':
39+
new_id.pop(len(new_id)-1)
40+
print(new_id) # 4
41+
if len(new_id) == 0:
42+
new_id += ['a']
43+
if len(new_id) >= 16:
44+
new_id = new_id[:15]
45+
if new_id[-1] == '.':
46+
new_id.pop(len(new_id)-1)
47+
48+
if len(new_id) == 2:
49+
new_id += [new_id[-1]]
50+
if len(new_id) == 1:
51+
new_id += [new_id[-1]]*2
52+
53+
return "".join(new_id)

programmers/난이도별/level01.실패율/HyeonJeong.py

-24
This file was deleted.

programmers/난이도별/level01.실패율/README.md

-3
This file was deleted.

programmers/난이도별/level01.실패율/dkdlelk99.py

-14
This file was deleted.

programmers/난이도별/level01.실패율/eyabc.js

-47
This file was deleted.

programmers/난이도별/level01.실패율/sangmandu.py

-15
This file was deleted.

0 commit comments

Comments
 (0)