C++ 算法提高 计数问题

首先此题很难去考虑字符串string等 毕竟“10”,“11”等不能直接由ASCALL码读出

考虑“拆分”

#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
    int n,count=0,i,x,t;
    cin>>n>>x;
    if(n<x)
    return 0;
    for(i=x;i<=n;i++)
    {
        for(t=i;t>0;t=t/10)
        {
            if(t%10==x)
            count++;
        }
        
    }
    cout<<count;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_47991812/article/details/108071858