题解 | 记数问题
记数问题
https://www.nowcoder.com/practice/28b2d9f2bf2c48de94a1297ed90e1732
// #include <bits/stdc++.h>
// using namespace std;
// int main() {
// int n,x;
// cin>>n>>x;
// int count=0;
// for(int i=1;i<=n;i++){
// int x0=i;
// while(x0!=0){
// if(x0%10==x){
// count+=1;
// }
// x0/=10;
// }
// }
// cout<<count;
// }
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,x;
cin>>n>>x;
char X=x+'0';
int count=0;
for(int i=1;i<=n;i++){
string a=to_string(i);
for(char b:a){
if(b==X) count+=1;
}
}
cout<<count;
}
查看20道真题和解析