题解 | 数字反转

数字反转

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")

全部评论

相关推荐

不愿透露姓名的神秘牛友
09-08 17:40
26秋招已经绝望了,投递了三十多家,只有几个AI面。
26届之耻将大局逆转:从8月15号开始,官网投了快100家,做了十几场笔试,已经挂了10家,还没面过一次!
我的秋招日记
点赞 评论 收藏
分享
09-06 15:20
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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