求1到n中x数字出现的次数

Kinghero King of the summit 2022-08-19 19:56:58 0
#include <iostream>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int count = 0;
    for(int i = 1;i <= n;i++)
    {
	    int a = i;
	    while(a > 0)//分离位数 
	    {
		    if(a % 10 == x)
		    {
			    count++;
		    }
		    a /= 10;
	    }
    }
    cout<<count; 
    return 0;
} 
{{ vote && vote.total.up }}