题解 | #小乐乐改数字#

小乐乐改数字

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;
}
全部评论

相关推荐

06-19 13:40
武汉大学 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-18 17:37
点赞 评论 收藏
分享
06-15 18:44
黄淮学院 Java
Lynn012:如果是居民楼还是算了吧,看着有点野呢
点赞 评论 收藏
分享
喜欢飞来飞去的雪碧在刷代码:可以试一试字节
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务