题解 | #小乐乐改数字#
小乐乐改数字
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;
}