不能用to_string吗
查看原帖
不能用to_string吗
872662
mengleo楼主2023/4/3 19:17
#include <bits/stdc++.h>

using namespace std;

int n, x, ans;

int main()
{
    cin >> n >> x;
    for(int i = 1; i <= n; i++)
    {
        string s = to_string(i);
        for(int j = 0; j < s.size(); j++)
        {
            if(s[j] - '0' == x)
            {
                ans++;
            }
        }
    }
    cout << ans;

    return 0;
}
2023/4/3 19:17
加载中...