题解 | #[NOIP2013]记数问题#
[NOIP2013]记数问题
https://ac.nowcoder.com/acm/problem/16538
将每个数字转化为字符串,遍历是否出现对应的数字字符,出现则+1
#include<bits/stdc++.h> using namespace std; int main(){ int n,count=0; char x; cin>>n>>x; for(int i=1;i<=n;i++){ string tmp=to_string(i); for(auto ch:tmp){ if(ch==x) count++; } } cout<<count; }