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
2 3 1
12 22 1
11 111 2
0 0 2
Sample output
5
-1
-1
hint [+]
Tip is hidden, click above [+] to show * * *
Source
2006 Zhejiang University computer and software engineering research on the real problem of life test
/*********************************
* Date: 2013-3-18
* Author: SJF0115
* question number: Tian Qin topic 1126: or A+b
* Source: http://acmclub.com/problem.php?id=1126
* Result: AC
* Source: 2006 Research on computer and software engineering of Zhejiang University The real Problem of life test
* Summary:
**********************************/
#include <stdio.h>
#include < stdlib.h>
int main ()
{
int k,a,b,n;
Freopen ("C:\\users\\sjf\\desktop\\acm.txt", "R", stdin);
while (scanf ("%d%d", &a,&b)! = EOF) {
if (A = = 0 && B = = 0) {break
;
}
scanf ("%d", &k);
n = 1;
while (k--) {
n *=;
}
Determine if K-bit is
the same if (A% n = = B% n) {
printf (" -1\n");
}
else{
printf ("%d\n", a+b);
}
}
return 0;
}