4 条题解

  • 1
    @ 2026-8-27 14:36:03
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        int n,x;
        cin>>n>>x;
        int cnt=0;
        for(int i=1;i<=n;i++){
            int t=i;
            while(t>0){
                if(t%10==x) cnt++;
                t/=10;
            }
        }
        cout<<cnt<<endl;
        return 0;
    }
    
  • 0
    @ 2026-8-28 9:27:57
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        int n, x;
        cin >> n >> x;
        int cnt = 0;
        for(int i = 1; i <= n; i++){
            int tmp = i;
            while(tmp > 0){
                int d = tmp % 10;
                if(d == x){
                    cnt++;
                }
                tmp = tmp / 10;    
            }
        }
        cout << cnt << endl;
        return 0;
    }
    
    • -1
      @ 2026-8-28 9:27:53
      #include<bits/stdc++.h>
      using namespace std;
      int n,x,sum=0;
      int main(){
          cin>>n>>x;
          for(int i=1;i<=n;i++){
              int t=i;
              while(t!=0){
                  if(t%10==x)sum++;
                  t/=10;
              }
          }cout<<sum;
          return 0;
      }
      
      • -2
        @ 2026-8-28 9:32:00
        #include<bits/stdc++.h>
        using namespace std;
        int main(){
            int n,x;
            cin>>n>>x;
            int s=0;
            for(i=1;i<=n;i++){
                int t=i;
                while(t){
                    int a=t%10;
                    if(a==x) s++;
                    t/=10;
                }
            }
            cout<<s;
            return 0;
        }
        
        • 1

        【深基4.例8】[NOIP2013 普及组] 计数问题

        信息

        ID
        110
        时间
        1000ms
        内存
        256MiB
        难度
        2
        标签
        递交数
        42
        已通过
        28
        上传者