1 solutions

  • 0
    @ 2024-6-11 10:29:27

    枚举+模拟(On On)

    • 【算法分析】枚举llrr之间的所有数,然后使用拆数模板进行拆数。
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int l,r;
        cin>>l>>r;
        int cnt=0;
        for(int i=l;i<=r;i++) //枚举范围
        {
            int t=i;
            while(t) //拆数模板
            {
                int ge=t%10;
                if(ge==2) cnt++;
                t/=10;
            }
        }
        cout<<cnt;
        return 0;
    }
    
    • 1

    Information

    ID
    429
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    4
    Accepted
    3
    Uploaded By