简单判断,pow函数

题目链接: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\n");
        else
            printf("%d\n",a+b);
    }
}
/**************************************************************
    Problem: 1015
    User: zpfbuaa
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1608 kb
****************************************************************/

 

作者: 伊甸一点

本文版权归作者伊甸一点所有,欢迎转载和商用(须保留此段声明),且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.