CCCHK '08 J2 - Lucky Number

View as PDF

Points: 3
Time limit: 1.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

In ancient Europe, people believed that their luck was dependent on a number. By summing up the digits of their birthday, they got a sum. By repeatedly adding the digits of the sum until a single digit number remains. This resultant number was called the "single digit representation". And the digit reflected their luck in their whole life.

In this question, a birthday will be given by a non-negative integer . Your program has to compute the single digit representation of the given number. Example:

Input Specification

The first input is an integer specifying the number of test cases. Then each input number appears on a line by itself.

Output Specification

For each test case, output the single digit representation of it.

Sample Input

4
1
10
19
999

Sample Output

1
1
1
9

• commented on Aug. 27, 2019, 3:19 p.m.

Why do I keep getting IRs?

• commented on Aug. 27, 2019, 4:22 p.m. edit 2

The input integers can be up to digits long. Integer.parseInt() cannot parse integers from the input greater than .

And in fact you cannot store a digit number as an int or even a long. Consider storing it as a String.

• commented on March 14, 2017, 5:33 p.m.

someonne give us a source code example please

• commented on March 14, 2017, 5:56 p.m. edited
print "Here's a novel idea: try it first."

• commented on March 14, 2017, 7:43 p.m.

This comment is hidden due to too much negative feedback. Click here to view it.

• commented on March 14, 2017, 11:40 a.m. edited

l o L

• commented on March 14, 2017, 12:30 p.m.

You're trying to read an integer of maximum length digits. That's far greater than the max value of an int.