2 solutions

  • 0
    @ 2026-1-26 8:57:35
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n,k,s=0;
        cin>>n>>k;
        for(int i=1;i<=n;i++)
        {
            int a=i;
            while(a!=0)
            {
                if(a%10==k)s++;
                a/=10;
            }
        }
        cout<<s;
    }
    
    • -1
      @ 2025-11-27 11:55:05

      C++ :

      #include <iostream>
      using namespace std;
      int check(int x, int y) {
      int cnt = 0;
      while (x > 0) {
      int tmp = x % 10;
      if (tmp == y) {
      cnt++;
      }
      x = x / 10;
      }
      return cnt;
      }
      int main() {
      int n, k;
      cin >> n >> k;
      int ans = 0;
      for (int i = 1; i <= n; i++) {
      ans += check(i, k);
      }
      cout << ans << endl;
      return 0;
      }
      
      • 1

      Information

      ID
      35
      Time
      1000ms
      Memory
      128MiB
      Difficulty
      6
      Tags
      # Submissions
      25
      Accepted
      10
      Uploaded By