https://www.luogu.org/problem/P1980
#include <iostream> #include <string.h> #include <stdio.h> using namespace std; char str[8]={0};
int countX(int n, int x) { memset(str, 0, 8); sprintf(str, "%d", n); int len=strlen(str); int iRet=0; char cDst='0' + x; for(int i = 0; i < len; i++) { if(str[i] == cDst) ++iRet; } return iRet; }
int main() { int n,x; cin >> n >> x; int iRet = 0; for(int i = 1; i <= n; i++) { iRet += countX(i, x); } cout << iRet<<endl; return 0; }