题解 | 记数问题
记数问题
https://www.nowcoder.com/practice/28b2d9f2bf2c48de94a1297ed90e1732
#include <stdio.h>
int main() {
int n, x, temp;
int i_cnt, x_total_cnt, i;
scanf("%d %d", &n, &x);
x_total_cnt = 0;
for(i = 1; i <= n; i++) {
i_cnt = 0;
temp = i;
while(temp) {
if(temp % 10 == x) {
i_cnt++;
}
temp = temp / 10;
}
x_total_cnt += i_cnt;
}
// 64 位输出请用 printf("%lld") to
printf("%d\n", x_total_cnt);
return 0;
}