题解 | #[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;
}


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务