题解 | #[NOIP2013]记数问题#
[NOIP2013]记数问题
https://www.nowcoder.com/practice/28b2d9f2bf2c48de94a1297ed90e1732
#include <stdio.h>
typedef unsigned int uint;
int main() {
uint x = 0;
uint n = 0;
while (2 == scanf("%u %u", &n, &x))
{
int count = 0;
for (int i = 1; i <= n; i++)
{
// 用临时变量存储i,方便进行遍历
uint tmp = i;
// 获取一个数字的每位一数并与数字x比较
while (tmp)
{
if (tmp % 10 == x)
{
count++;
}
tmp /= 10;
}
}
printf("%u\n", count);
}
return 0;
}


阿里云成长空间 794人发布