Digits
SRM 86 · 2002-05-07 · by bkramer
SRM 86 · 2002-05-07 · by bkramer · Simple Math
Problem Statement
Problem Statement
The smallest digit in an integer is defined to be the digit closest to 0 out of
the possible 0 - 9.
Create a class Digits that contains the method sumDigits, which takes in the parameterint[] , numbers, and returns the sum of the smallest digit from all the
numbers.
Create a class Digits that contains the method sumDigits, which takes in the parameter
Notes
- the integer 0 is seen as having a smallest digit of 0
- no integers will have leading 0's (99 will never be seen as 099)
Constraints
- numbers has between 1 and 20 elements, inclusive
- Each element of numbers is between -1000 and 1000, inclusive
- All integers are considered to be base 10, and will only have digits 0 - 9
Examples
0)
{987}
Returns: 7
7 is the smallest digit out of the possible digits 7, 8, and 9.
1)
{987, -990}
Returns: 7
7 is the smallest digit of 987, and 0 is the smallest digit from -990. 7 + 0 = 7
2)
{48, -88, 46, -45, 22}
Returns: 22
3)
{675,-946,999,18}
Returns: 19
4)
{87}
Returns: 7
Submissions are judged against all 94 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class Digits with a public method int sumDigits(vector<int> numbers) · 94 test cases · 2 s / 256 MB per case