题解 | #数字反转#

数字反转

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

#include "stdio.h"

int numReverse(int num){
    int sum = 0;
    while (num!=0){
        sum = sum*10 + num%10;
        num = num/10;
    }
    return sum;
}

int main(){
    int num1,num2;int sum1,sum2;
    while (scanf("%d%d",&num1,&num2)!=EOF){
        sum1 = num1 + num2;
        num1 = numReverse(num1);
        num2 = numReverse(num2);
        sum2 = num1 + num2;
        if(sum1 == numReverse(sum2))
            printf("%d\n",sum1);
        else
            printf("NO\n");
    }
}

全部评论

相关推荐

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