题解 | #小乐乐改数字#

小乐乐改数字

https://www.nowcoder.com/practice/fcd30aac9c4f4028b23919a0c649824d

#include <stdio.h>
#include <math.h>
int main() {
    long long n;            // 输入
    long long res = 0;      // 输出
    int arr[10];            // 存储n每位数的判定结果(1为奇,0为偶)
    int nBit;               // n某数位的值
    int arrStopIndex = 0;   // arr的截止索引,表示arr有几个有效数字
    scanf("%lld", &n);

    for (int i = 0; n > 0; i++) {
        nBit = n % 10;  // n的余数,表示n的最低位
        if (nBit % 2 == 0) {
            arr[i] = 0;
        } else {
            arr[i] = 1;
        }
        n /= 10;        // n的商,保存到下一轮循环
        arrStopIndex++;
    }

    //
    for (int i = 0; i < arrStopIndex; i++) {
        if (arr[i] == 1) {
            res += 1 * pow(10, i);
        }
    }

    printf("%lld\n", res);

    return 0;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
02-12 18:14
RT,这周五就是情人节了,前女友给我发了消息,我该不该回?
Yoswell:原则上来说让她滚,但是本着工作很累下班想吃瓜的心态,我觉得你可以回一下
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务