文章

13

粉丝

386

获赞

2

访问

59.7k

头像
根据题意反转即可
P1276 上海交通大学机试题
发布于2022年3月5日 16:31
阅读数 4.7k

#include <iostream>
#include <cstdio>

using namespace std;

int reverse(int x){
    int res = 0;
    while(x != 0){
        res = res * 10 + x % 10;
        x /= 10;
    }
    return res;
}

int main(){
    int x1, y1, res1;
    int x2, y2, res2;
    while(scanf("%d%d", &x1, &y1) != EOF){
        res1 = x1 + y1;
        x2 = reverse(x1);
        y2 = reverse(y1);
        res2 = x2 + y2;
        if(res2 == reverse(res1)) printf("%d\n", res1);
        else printf("NO\n");
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发