[Boj]1475 :방 번호

2024. 8. 4. 11:53Algorithm

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])