1. 2016๋
def solution(a, b):
date = ['FRI','SAT','SUN','MON','TUE','WED','THU']
month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
cnt = 0
for i in range(a-1):
cnt += month[i]
ans = (cnt + b) % 7
return date[ans-1]
2. ๋ฌธ์์ด ๋ค๋ฃจ๊ธฐ ๊ธฐ๋ณธ
def solution(s):
if len(s) == 4 and s.isdigit():
return True
elif len(s) == 6 and s.isdigit():
return True
else:
return False
3. ๋ฌธ์์ด ๋ด๋ฆผ์ฐจ์์ผ๋ก ๋ฐฐ์นํ๊ธฐ
def solution(s):
s = list(s)
s.sort(reverse=True)
return ''.join(s)
4. ์ฝ์์ ํฉ
def solution(n):
arr = []
for i in range(1,n+1):
if n % i == 0:
arr.append(i)
return sum(arr)
5. ์์ธ์์ ๊น์๋ฐฉ ์ฐพ๊ธฐ
def solution(seoul):
answer = "๊น์๋ฐฉ์ " + str(seoul.index("Kim")) + "์ ์๋ค"
return answer
6. ์๋ฐ์๋ฐ์๋ฐ์๋ฐ์๋ฐ์?
def solution(n):
ans = ''
for i in range(n):
if i % 2 == 0:
ans += '์'
else:
ans += '๋ฐ'
return ans
7. ๋ฌธ์์ด์ ์ ์๋ก ๋ฐ๊พธ๊ธฐ
def solution(s):
if s[0] == "-":
k = int(s[1:]) * -1
return k
else:
k = int(s[0:])
return k
8. ์์ ์ฐพ๊ธฐ
import itertools
import math
def solution(numbers):
arr = []
imp = []
ans = 0
for i in range(1,len(numbers)+1):
num = list(map(''.join, itertools.permutations(numbers,i)))
arr.append(num)
arr = sum(arr,[])
arr = list(set(arr))
for i in arr:
imp.append(int(i))
imp = list(set(imp))
imp.sort()
for k in imp:
cnt = 0
sqrt = int(math.sqrt(k))
if k != 0 and k != 1:
for i in range(2,sqrt+1):
if k % i == 0:
cnt += 1
if cnt == 0:
ans += 1
return ans
๋ถ์ > ํด๋น ์๋ฅผ ์ ๊ณฑ๊ทผ ์ดํ์ ์๋ก ํ๋์ฉ ๋๋์ด ๋ดค์ ๋, ๋๋์ด ๋จ์ด์ง๋ ์๊ฐ 0๊ฐ๋ผ๋ฉด ์ด ์๊ฐ ์์์์ ์ ์ ์๋ค๋ ๊ฒ์ด ์ค์ํ ํฌ์ธํธ์ธ ๋ฌธ์ ์๋ค.
9. ์์ ์ํธ
def solution(s, n):
ans = ''
for i in s:
if i.isupper():
if ord(i) + n > ord('Z'):
ans += chr(ord(i) + n - ord('Z') + ord('A') - 1)
else:
ans += chr(ord(i) + n)
elif i.islower():
if ord(i) + n > ord('z'):
ans += chr(ord(i) + n - ord('z') + ord('a') - 1)
else:
ans += chr(ord(i) + n)
else:
ans += ' '
return ans
10. ์ต์ ์ง์ฌ๊ฐํ
def solution(sizes):
w = []
h = []
for i in range(len(sizes)):
if sizes[i][0] > sizes[i][1]:
w.append(sizes[i][0])
h.append(sizes[i][1])
else:
w.append(sizes[i][1])
h.append(sizes[i][0])
return max(w) * max(h)
'Algorithm > ์ฝ๋ฉํ ์คํธ ์คํฐ๋' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ฝ๋ฉํ ์คํธ ์คํฐ๋ 3์ฃผ์ฐจ (0) | 2022.05.16 |
---|---|
์ฝ๋ฉํ ์คํธ ์คํฐ๋ 1์ฃผ์ฐจ (4/25 ~ 5/1) (0) | 2022.05.01 |