[Boj]1475 :방 번호
2024. 8. 4. 11:53ㆍAlgorithm
1. problem :
https://www.acmicpc.net/problem/1475
2. solution 1 :
def calculate_min_sets(room_number: str) -> int:
counts = [0] * 10
for digit in room_number:
counts[int(digit)] += 1
counts[6] = (counts[6] + counts[9] + 1) // 2
counts[9] = counts[6] # 9는 더 이상 개별적으로 고려하지 않음
return max(counts[:9]) # counts[9]는 이미 6과 통합되어 있으므로, 0~8까지만 고려
# 테스트
room_number = input().strip()
print(calculate_min_sets(room_number))
3. solution 2 :
a = input()
freq = {str(i):0 for i in range(9)}
for i in a:
if i == '9':
freq['6'] += 1
else:
freq[i] += 1
freq['6'] = sum(divmod(freq['6'],2))
sorted_freq = sorted(freq.items(), key=lambda item: item[1], reverse=True)
print(sorted_freq[0][1])
'Algorithm' 카테고리의 다른 글
[Boj] 10807번 : 개수 세기 (0) | 2024.08.04 |
---|---|
[Boj]3273번 : 두 수의 합 (0) | 2024.08.04 |
[Leetcode]981. Time Based Key-Value Store (0) | 2024.08.03 |
[Leetcode]1493. Longest Subarray of 1's After Deleting One Element (0) | 2024.08.03 |
[Leetcode] 875. Koko Eating Bananas(x) (0) | 2024.08.03 |