본문 바로가기
구름톤 챌린지

[구름톤 챌린지] 1주차_4~ 5일차 학습

by 깁갑수 2023. 8. 20.
목차

 내 풀이 과정

 

합을 구하는것은 어렵지 않은데 올바른 햄버거를 잘 찾아야한다.

 input과 map을 이용해 햄버거 재료갯수와 재료의 맛의 정도를 입력받아줬다.

햄버거 재료의 오름, 내림차순을 점검하기위해 햄버거리스트의 맥스값을 기준으로 상행, 하행 파트를 나누고 오름, 내림차순이 되어있는지 검토하여 결과값을 도출한다.

 

n = input()
k = []
k=list(map(int, input().split()))
peakIdx = k.index(max(k))
upperPart = k[peakIdx:]
underPart = k[:peakIdx]
result = sum(k)
for x in range(len(upperPart)-1):
	if upperPart[x] < upperPart[x+1]: result = 0
for x in range(len(underPart)-1):
	if underPart[x] > underPart[x+1]: result = 0

print (result)

정해코드

여러가지 해결법으로 해설되었지만 내가 풀이한 방법과 비슷하면서도 뭔가 다른 방법으로 해결되었다.

# sort() 사용

N = int(input())
arr = list(map(int, input().split()))

MAX = max(arr)
maxIndex = arr.index(MAX)

left = arr[:maxIndex]
right = arr[maxIndex:]

left.sort()
right.sort(reverse=True)

sortedArr = left + right

check = True

for i in range(N):
	if arr[i] != sortedArr[i]:
		check = False
		break

if check:
	print(sum(arr))
else:
	print(0)

 

# sorted()사용

N = int(input())
arr = list(map(int, input().split()))

MAX = max(arr)
maxIndex = arr.index(MAX)

left = arr[:maxIndex]
right = arr[maxIndex:]

sortedLeft = sorted(left)
sortedRight = sorted(right, reverse=True)

sortedArr = sortedLeft + sortedRight

check = True

for i in range(N):
	if arr[i] != sortedArr[i]:
		check = False
		break

if check:
	print(sum(arr))
else:
	print(0)

 

# sort, for 사용

N = int(input())
arr = list(map(int, input().split()))

MAX = max(arr)
maxIndex = arr.index(MAX)

left = arr[:maxIndex]
right = arr[maxIndex:]

left.sort()
right.sort(reverse=True)

sortedArr = left + right

for i in range(N):
	if arr[i] != sortedArr[i]:
		print(0)
		break
else:
	print(sum(arr))

 

Day5 이진수 정렬 - 구름LEVEL (goorm.io)

내 풀이 과정

이번 문제는 최대한 라인수를 줄여볼까 하고 고민을 좀해봤다.

10진수와 2진수를 동시에 비교할 경우가 생기는것 같아서 리스트 안에 10진수와 2진수의 1의 합을 동시에 배치했고 sort를 통해 줄을 세워봤다.

N,K = map(int, input().split())
a = map(int, input().split())
a2b = [[x, sum(map(int,format(x, 'b')))] for x in a]
a2b.sort(key = lambda x:(-x[1], -x[0]))
print(a2b[K-1][0])

 

정해코드

나랑 너무 다른걸...

N, K = map(int, input().split())
arr = list(map(int, input().split()))

newArr = []

for i in range(N):
	binaryNumber = bin(arr[i])[2:]
	
	count = 0
	
	for c in binaryNumber:
		if c == '1':
			count += 1
	
	newArr.append( [count, arr[i]] )

newArr.sort(reverse=True)
print(newArr[K - 1][1])

 

 

"갑수야 반갑수"에는 쿠팡파트너스 등 제휴링크가 포함 되어 있으며 수수료를 제공받을 수 있습니다.