Skip to content

Commit

Permalink
[BOJ] 18406번 럭키 스트레이트 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
heerucan committed Apr 8, 2022
1 parent f402a5b commit 08d51e3
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CodingTest/CH3 그리디/3-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 거스름돈
n = int(input())
count = 0
coinArray = [500, 100, 50, 10]

for coin in coinArray:
count += n//coin # 거스름돈을 coin으로 나누고 나온 몫
n %= coin # n을 coin으로 나눈 나머지를 n에 대입

print(count)
16 changes: 16 additions & 0 deletions CodingTest/CH3 그리디/3-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 큰 수의 법

n, m, k = map(int, input().split())
result = 0
data = list(map(int, input().split()))

data.sort()

while m > 0:
for i in range(k):
result += data[-1]
m -= 1
result += data[-2]
m -= 1

print(result)
14 changes: 14 additions & 0 deletions CodingTest/CH3 그리디/3-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 숫자 카드 게임

# n : 행의 개수
# m : 열의 개수

n, m = map(int, input().split())
minData = []
for i in range(n):
data = list(map(int, input().split()))
data.sort()
data[0]
minData.append(data[0])
minData.sort()
print(minData[-1])
14 changes: 14 additions & 0 deletions CodingTest/CH3 그리디/3-4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 1이 될 때까지

n, k = map(int, input().split())
count = 0

while n >= 1:
if n%k == 0:
n //= k
count += n//k
else:
n -= 1
count += 1

print(count)
8 changes: 8 additions & 0 deletions CodingTest/CH3 그리디/곱하기혹은더하기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
s = list(map(int, input()))
result = 1

for i in s:
if i != 0:
result *= i

print(result)
5 changes: 5 additions & 0 deletions CodingTest/CH3 그리디/만들수없는금액.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import itertools

n = int(input())
coin = list(map(int, input().split()))

20 changes: 20 additions & 0 deletions CodingTest/CH3 그리디/모험가길드.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 답안 참고함

n = int(input())
fear = list(map(int, input().split()))

fear.sort() # 공포도를 정렬하고 [1, 2, 2, 2, 3]

groupCount = 0 # 그룹의 수
traveler = 0 # 그룹에 현재 포함된 모험가 수

# 먼저 공포도가 가장 큰 사람한테 배치
# 공포도사람 <= 팀원수

for i in fear:
traveler += 1
if traveler >= i: # 현재 모험가 수 >= 공포도 -> 그룹 결성
groupCount += 1
traveler = 0 # 그리고 다시 그룹을 초기화 시킴

print(groupCount)
9 changes: 9 additions & 0 deletions CodingTest/CH3 그리디/문자열뒤집기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
s = list(map(int, input()))
count = 0
for i in range(len(s)):
if s[i-1] != s[i]:
count += 1

print(count//2)


12 changes: 12 additions & 0 deletions CodingTest/CH3 그리디/볼링공고르기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sys
from itertools import combinations

n, m = list(map(int, input().split()))
k = list(map(int, sys.stdin.readline().split()))

count = 0
for i in combinations(k, 2):
if i[0] != i[1]:
count += 1

print(count)
15 changes: 15 additions & 0 deletions CodingTest/CH4 구현/18406.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
n = list(input())
half = int(len(n)/2)


def findsum(array):
result = 0
for i in array:
result += int(i)
return result


if findsum(n[:half]) != findsum(n[half:]):
print("READY")
else:
print("LUCKY")
Empty file added CodingTest/CH4 구현/18406.py
Empty file.

0 comments on commit 08d51e3

Please sign in to comment.