This problem is also very simple ~ mainly to convert the input into a string (storing large numbers, manipulating the character array)
Test instructions
24:2 + 4 = 6 Output 6
39:3 + 9 = 12, 1 + 2 = 3 Output 3
999:9 + 9 + 9 = 27, 2 + 7 = 9 Output 9
The Java code is as follows:
ImportJava.util.*;ImportJava.io.*; Public classmain{ Public Static voidMain (string[] arg) {Scanner Scan=NewScanner (NewBufferedinputstream (system.in)); String s; while(true) {s=Scan.next (); Char[] cs =S.tochararray (); if(Cs[0] = = ' 0 '){ Break; } if(cs.length==1) {System.out.println (s); Continue; } System.out.println (Getsum (CS)); } scan.close (); } Static intGetsum (Char[] CS) { intsum = 0; while(cs.length!=1) {sum= 0; for(inti = 0; I! = cs.length; i + +) {sum= cs[i]-' 0 ' +sum; } CS=string.valueof (sum). ToCharArray (); } returnsum; }}
hdoj-acm1013 (JAVA)