题解 | #进制A+B#

进制A+B

https://www.nowcoder.com/practice/6187581174ac48278ca3bccf8d534897

#include <stdio.h>
int turn(int x) {
    int yua;
    int goal = 0;
    int power = 1;
    yua = x;
    while (yua) {
        int s = yua % 16;
        goal += power * s;
        power *= 16;
        yua /= 16;
    }
    return goal;
}
int turn1(int y) {
    int yua1;
    int goal1 = 0;
    int power1 = 1;
     yua1 = y;
    while (yua1) {
        int s1 = yua1 % 16;
        goal1 += power1 * s1;
        power1 *= 16;
        yua1 /= 16;
    }
    return goal1;
}
int main() {
    int a, b;
    while (scanf("%x", &a) != EOF && scanf("%o", &b) != EOF) {
        int c = turn(a);
        int d = turn1(b);
        printf("%d",c + d);
    }
    return 0;
}

全部评论

相关推荐

废铁汽车人:秋招真是牛鬼蛇神齐聚一堂
点赞 评论 收藏
分享
kyw_:接好运
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务