還是A+B
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9172 Accepted Submission(s): 4504
Problem Description
讀入兩個小於10000的正整數A和B,計算A+B。需要注意的是:如果A和B的末尾K(不超過8)位數字相同,請直接輸出-1。
Input
測試輸入包含若干測試用例,每個測試用例佔一行,格式爲"A B K",相鄰兩數字有一個空格間隔。當A和B同時爲0時輸入結束,相應的結果不要輸出。
Output
對每個測試用例輸出1行,即A+B的值或者是-1。
Sample Input
1 2 1
11 21 1
108 8 2
36 64 3
0 0 1
Sample Output
3
-1
-1
100
呵呵
一次A掉,太水了,不用二十行代碼!!用pow()函數來做
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int t,a,b,k;
while(cin>>a>>b>>k,a,b)
{
t=pow(10,k);
if( a % t == b % t)
{
cout<<"-1"<<endl;
}
else
cout<<a+b<<endl;
}
return 0;
}