티스토리 뷰
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | let input = readLine()! var array = [Int]() var cards = [0,0,0,0,0,0,0,0,0,0] for i in input{ array.append(Int(i.description)!) } for number in array{ cards[number] += 1 } var cardsExceptSixAndNine = [Int]() for i in 0..<cards.count{ if(i == 6 || i == 9){ cardsExceptSixAndNine.append(0) } else { cardsExceptSixAndNine.append(cards[i]) } } let max = cardsExceptSixAndNine.max()! let six = cards[6] let nine = cards[9] if(max*2 >= six+nine){ print(max) } else{ let sub = six+nine-max*2 let more = Int((Double(sub) / 2.0).rounded()) print(max + more) } | cs |
6과 9를 제외한 숫자는 카드 팩에 하나씩 들어있으므로 해당 숫자 중 빈도수가 가장 높은 값을 먼저 구하고
6과 9의 빈도수를 더한 값과 비교하여 카드 팩의 최소 개수를 구한다.
'Algorithm > Baekjoon Online Judge' 카테고리의 다른 글
9012번 '괄호' (0) | 2018.02.23 |
---|---|
10828번 '스택' (0) | 2018.02.23 |
1157번 '단어 공부' (0) | 2018.02.23 |
2108번 '통계학' (0) | 2018.02.23 |
1427번 '소트인사이드' (0) | 2018.02.23 |
댓글