记数问题_牛客题霸_牛客网
#include <stdio.h> int main() { int a, b; int count=0;//用于计算b出现次数 while (scanf("%d %d", &a, &b) != EOF) { // 注意 while 处理多个 case // 64 位输出请用 printf("%lld") to for(int i=1;i<=a;i++)//用于产生1到n的所有整数,a就是n { int j=i;//不能破坏i,但要用i,故把i值赋给j while(j>0)//取j每位上的数字进行比对 { int k=0;//存放最低位上数字 k=j%10;//取低位赋值给k if (k==b) //检测 { count++; } j=j/10;//省略最低位 } } printf("%d",count); } return 0; }