题解 | #数字反转#

数字反转

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

//#include<iostream>
//#include<cstdio>
#include <stdio.h>

//using namespace std;

int reverse(int x){
    //求反序数
    int revx=0;
    while(x!=0){
        revx *= 10;
        revx += x%10;
        x /= 10;
    }
    return revx;
}

int main(){
    int a,b,c;int a1,b1,c1;
    while(scanf("%d%d",&a,&b)!=EOF){
        c=a+b;
        a1=reverse(a);
        b1=reverse(b);
        c1=reverse(c);
        if(a1+b1==c1)printf("%d\n",c);
        else printf("NO");

    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务