Connection Status:
Competition Arena > CommonDigits
SRM 128 · 2003-01-06 · by vorthys
Class Name: CommonDigits
Return Type: int
Method Name: digit
Arg Types: (int)
Problem Statement

Problem Statement

Create a class CommonDigits with a method digit that takes an int num and returns the single digit that occurs most often in the decimal representation of num (without leading zeros). If several digits occur the same number of times, give preference to the one whose leftmost (most significant) occurrence is farthest to the left.

Constraints

  • num is between 1 and 1000000000, inclusive.
Examples
0)
123
Returns: 1

All digits occur the same number of times so return the leftmost.

1)
102030
Returns: 0
2)
79888799
Returns: 9
3)
1
Returns: 1
4)
1000000000
Returns: 0

Submissions are judged against all 31 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class CommonDigits with a public method int digit(int num) · 31 test cases · 2 s / 256 MB per case

Submitting as anonymous