1 条题解

  • 0
    @ 2026-1-30 19:53:39
    #include<bits/stdc++.h>
    using namespace std;
    // [1] 存储输入的上限n
    int n;
    // [2] 统计数字8出现的总次数(简化变量名)
    int s = 0;
    
    int main() {
        cin >> n; // [3] 输入上限n
        // [4] 遍历1到n的所有数
        for(int i = 1; i <= n; i++) {
            int t = i; // [5] 临时变量,用于逐位拆分
            // [6] 逐位拆分当前数,检查每一位是否为8
            while(t > 0) {
                if(t % 10 == 8) s++;
                t /= 10;
            }
        }
        cout << s; // [7] 输出数字8出现的总次数
        return 0;
    }
    
    • 1

    信息

    ID
    1249
    时间
    1000ms
    内存
    256MiB
    难度
    1
    标签
    递交数
    1
    已通过
    1
    上传者