题解 | #数字反转#

数字反转

https://www.nowcoder.com/practice/2687c5c174cb4f938bdae01f0a19490c

#include <bits/stdc++.h>
using namespace std;

string f(int a, int b){
    int sum = a+b;
    string temp = to_string(sum);
    string s1 = to_string(a);
    string s2 = to_string(b);
    reverse(temp.begin(),temp.end());
    reverse(s1.begin(),s1.end());
    reverse(s2.begin(),s2.end());
    return stoi(temp) == stoi(s1)+stoi(s2)?to_string(sum):"NO";
}

int main() {
    int a, b;
    while (cin >> a >> b) { // 注意 while 处理多个 case
        cout<<f(a,b)<<endl;
    }
}
// 64 位输出请用 printf("%lld")

qd

全部评论

相关推荐

点赞 评论 收藏
分享
11-06 16:50
门头沟学院 Java
用微笑面对困难:word打字比赛二等奖的我,也要来凑合凑合
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务