题目链接: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 ",sum) : printf("NO "); } } /************************************************************** Problem: 1089 User: zpfbuaa Language: C++ Result: Accepted Time:0 ms Memory:1520 kb ****************************************************************/