题解 | 数字反转

数字反转

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

#include <iostream>
#include<algorithm>
using namespace std;

int main() {
    char a[6], b[6];
    while (scanf("%s %s",a,b)!=EOF) { // 注意 while 处理多个 case
        int sum1=atoi(a)+atoi(b);
        string s1=to_string(sum1);
        reverse(s1.begin(),s1.end());
        string s2=a;
        string s3=b;
        reverse(s2.begin(),s2.end());
        reverse(s3.begin(),s3.end());
        int a1=stoi(s2);
        int b1=stoi(s3);
        int sum2=a1+b1;
        if(stoi(s1)==sum2)printf("%d\n",sum1);
        else printf("NO\n");
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务