题目链接:http://ac.jobdu.com/problem.php?pid=1015
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
// // 1015 还是A+B.cpp // Jobdu // // Created by PengFei_Zheng on 09/04/2017. // Copyright © 2017 PengFei_Zheng. All rights reserved. // #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <cmath> using namespace std; int a, b, k; int main(){ while(scanf("%d%d%d",&a,&b,&k)!=EOF){ if(0==a && 0==b) break; int num = pow(10,k); int tmp1 = a % num ; int tmp2 = b % num ; //tmp1 = (tmp1+num)%num; 其实没有必要的两行代码 //tmp2 = (tmp2+num)%num; if(tmp1 == tmp2) printf("-1 "); else printf("%d ",a+b); } } /************************************************************** Problem: 1015 User: zpfbuaa Language: C++ Result: Accepted Time:0 ms Memory:1608 kb ****************************************************************/