题解 | #数字反转#

数字反转

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

全部评论

相关推荐

04-03 22:41
兰州大学 C++
老六f:有时候是HR发错了,我之前投的百度的后端开发,他给我发的算法工程师,但是确实面的就是百度开发
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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