아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Special Serial Numbers

시간 제한1초메모리 제한1024 MB

요약
N자리 수가 주어질 때, 어떤 숫자가 절반을 초과해 등장하는 가장 큰 특별한 수를 그 수 이하에서 찾는다.
난이도

보통10점 중 6점

유형
구현, 수학
정답자
아직 제출이 없습니다

문제

Each newborn calf on Farmer John's farm receives a brand new N-digit (1 ≤ N ≤ 100) serial number, a positive integer larger than any other cow's serial number on the farm. Obviously, the larger the serial number, the younger the cow.

Each cow becomes very fond of her number and often boasts about it. The cows are especially proud of serial numbers in which more than half (not just half!) of the digits are the same. For example, in the number 23522, the digit 2 appears in 3 out of the 5 digit places; the number 12342, though, has no digit that appears as a strict majority. Cows with serial numbers that contain a single majority digit are called 'special'; the rest of the cows are 'ordinary'.

Naturally, ordinary cows are quite envious of special cows. Sometimes in the past, they have even resorted to bullying special cows. Of course, given the growth rate of cows, a cow can only bully cows that are younger than it. In fact, an ordinary cow will bully the oldest special cow younger than she is. Unfortunately, cows have a tough time figuring out which cow that would be. Given a cow's serial number, determine which special cow she should bully. If the cow is already special, then output her own serial number.

입력

  • Line 1: The serial number of the cow that might be a bully

출력

  • Line 1: An integer that is the serial number of the cow that the cow might bully.

예제1

  1. 예제 1

    입력
    1234
    
    예상 출력
    1311