1 条题解

  • 0
    @ 1972-10-16 9:09:49

    练4.3 3个连续数

    解题思路

    从 100 开始连续输出 3 个整数,每输出一次加 1。

    正确性说明

    连续自然数相差 1,因此得到 100、101、102。

    易错点

    每个数字单独一行。

    复杂度

    本题规模固定,时间 O(1),额外空间 O(1)。

    参考代码(C++11)

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        for (int x = 100; x <= 102; x++)
            cout << x << "\n";
        return 0;
    }
    
    • 1