在一行中输入两个整数
,用空格隔开。其中
表示区间上界,
表示要统计的数字。
输出一个整数,表示数字
在区间
中出现的次数。
11 1
4
在中,数字 1 出现了 4 次。
20 1
12
在区间到
中,数字 1 出现在
中,共 12 次。
#include<stdio.h>
int Cal_count(int n,int x)
{
int i = 0;
int g = 0;
int count = 0;
for(i=1;i<=n;i++)
{
int j = i;
while(j)
{
g = j%10;
if(g==x)
{
count++;
}
j=j/10;
}
}
return count;
}
int main()
{
int n = 0;
int x = 0;
scanf("%d %d",&n,&x);
int ret = Cal_count(n,x);
printf("%d",ret);
return 0;
} #include <stdio.h>
int oo(int x,int y,int num)
{
if(x%10==y)
{
num=num+1;
}
if(x<10)
{
return num;
}
else
{
return oo(x/10,y,num);
}
}
int main()
{
int x,y;
scanf("%d %d",&x,&y);
int i=0;
int d=0;
for(i=1;i<=x;i++)
{
int c=0;
int num=0;
c=oo(i,y,num);
d=d+c;
}
printf("%d",d);
return 0;
} #include <stdio.h>
int main() {
int n,x;
int sum = 0;
scanf("%d %d", &n, &x);
for (int i = 1; i <= n ;i++ ) {
int tmp = i;
while (tmp) {
if(tmp % 10 == x)
sum++;
tmp /= 10;
}
}
printf("%d", sum);
return 0;
} #include <stdio.h>
int main()
{
int n, x;
int count = 0;
scanf("%d %d", &n, &x);
for (int i = 1; i <= n; i++)//每一次循环判断一个数,直到n为止
{
int a = i;
while (a)//利用while循环判断每一位数字,直到a等于0,
{
if (a % 10 == x)//如果个位上的数字是x,count加一
count++;
a /= 10;//将个位上的数字去除,十位上的数字变成个位上的数字
}
}
printf("%d", count);
return 0;
} #include <stdio.h>
int main() {
int n, x, cnt = 0;
while (scanf("%d %d", &n, &x) != EOF) {
int tmp;
for (int i = 1; i <= n; i++) {
tmp = i;
while (tmp) {
if (tmp % 10 == x) {
cnt++;
}
tmp /= 10;
}
}
printf("%d\n", cnt);
}
return 0;
}
#include <stdio.h>
int main() {
int n, x,count=0,b;
while (scanf("%d %d\n", &n, &x) == 2)
{
for(int i=1;i<=n;i++)
{
b=i;
while(b)
{
if(b%10==x)
{
count++;
}
b/=10;
}
}
printf("%d\n",count);
}
return 0;
}