UberOA #12
Sensor Readings Digit-Sum Mode
Estimated EasyJudge-ready
Topics (AI-labelled)HashingBits & Math
Repeatedly replace each integer with the sum of its digits until every number is a single digit. Return the digit that appears most often; if counts are tied, take the larger digit.
This site's standard input/output is stated explicitly.
Input
The first line contains n, and the second line contains n non-negative integers; 1≤n≤100, 0≤a[i]≤1000000.
Output
Output one integer answer.
Example 1
Input:
4
123 456 789 101
Output:
6
Example 2
Input:
2
1 2
Output:
2
Example 3
Input:
3
0 9 18
Output:
9
Example notes
Example 1: the digital roots are 6, 6, 6, 2, so return 6. Example 2: 1 and 2 appear once each; on the tie, take 2. Example 3: the digital roots are 0, 9, 9, so return 9; a positive multiple of 9 does not have digital root 0.
Editorial
Loading solution…