8 solutions

  • 0
    @ 2025-11-29 15:39:30
    #include <iostream>
    using namespace std;
    
    int main() {
        int n;
        cin >> n;
        int count = 0;
        
        // 遍历每个可能的数字d(1-9)
        for (int d = 1; d <= 9; d++) {
            // 生成由d组成的优美数字:d, dd, ddd, dddd等
            long long num = 0;
            for (int length = 1; length <= 4; length++) { // 最多4位,因为2025是4位数
                num = num * 10 + d;
                if (num <= n) {
                    count++;
                } else {
                    break; // 更长的数字也会超过n,所以直接跳出循环
                }
            }
        }
        
        cout << count << endl;
        return 0;
    }
    

    Information

    ID
    2886
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    7
    Tags
    # Submissions
    19
    Accepted
    9
    Uploaded By