Fork me on GitHub

题目1089:数字反转(简单数字转换)

题目链接:http://ac.jobdu.com/problem.php?pid=1089

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

参考代码:

//
//  1089 数字反转.cpp
//  Jobdu
//
//  Created by PengFei_Zheng on 04/05/2017.
//  Copyright © 2017 PengFei_Zheng. All rights reserved.
//
 
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
 
using namespace std;
 
int reverse(int x){
    int tmp = x;
    int ans = 0;
    while(tmp!=0){
        ans = ans*10 + tmp%10;
        tmp/=10;
    }
    return ans;
}
int n;
int main(){
    scanf("%d",&n);
    while(n--){
        int a,b;
        scanf("%d %d",&a,&b);
        int sum = a+b;
        reverse(sum) == reverse(a) + reverse(b) ? printf("%d\n",sum) : printf("NO\n");
    }
}
/**************************************************************
    Problem: 1089
    User: zpfbuaa
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1520 kb
****************************************************************/

 

posted @ 2017-05-04 21:17  伊甸一点  阅读(1090)  评论(0编辑  收藏  举报