-
Title Description:
-
read in two positive integers a and B less than 10000, calculate a+b. It is important to note that if the end of A and B (not more than 8) digits are the same, please output-1 directly.
-
Input:
-
The test input contains several test cases, one row for each test case, the format "A B K", and two adjacent numbers with a space interval. When A and B are at the end of the 0 o'clock input, the corresponding result is not output.
-
Output:
-
Output 1 rows For each test case, that is, the value of a+b or 1.
-
Sample input:
-
1 2 111 21 1108 8 236 64 30 0 1
-
Sample output:
-
3-1-1100
Just judge the end of k digits, see if the K-bit is the same
1 ImportJava.util.Scanner;2 3 Public classmain{4 Public Static voidMain (String[]args) {5 intA=0,b=0,k=0;6Scanner in=NewScanner (system.in);7 while(In.hasnext ()) {8A=in.nextint ();9b=in.nextint ();Tenk=in.nextint (); One if(a==0&&b==0) A Break; - inta=a,b=B; - Booleanflag=false; the for(inti=0;i<k;i++,a/=10,b/=10){ - if(a%10!=b%10){ -flag=true; - Break; + } - } + if(flag) System.out.println (A +B); A ElseSystem.out.println (-1); at } - } - } - /************************************************************** - problem:1015 - user:0000h in Language:java - result:accepted to time:80 Ms + memory:15460 KB - ****************************************************************/
Topic 1015: Or A+b