Topic 1015: Or A+b

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.