-
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
#include <iostream>using namespacestd;intMain () {intA,b,k,i; while(cin>>a>>b>>k) { if(a==0&& b==0)return 0; Else{ intc=a+b; BOOLflag=false; for(i=0; i<k;i++){ if(a%Ten!=b%Ten) {flag=true; Break; } A=a/Ten; b=b/Ten; } if(flag) cout<<c<<Endl; Elsecout<<"-1"<<Endl; }} return 0;}
1015. or the A+b