1 条题解
-
0
练25.1 打老虎
解题思路
循环从 1 到 5,每次输出当前数并换行。诗歌只是背景,实际只要求输出五个数字。
正确性说明
按上述推导执行:每次仅处理当前输入或当前步骤,并把它对答案的贡献计入对应状态。所有需要处理的情况均被覆盖,结束时保存的量就是题目所求。
易错点
不输出诗歌或标题。
复杂度
时间 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 i = 1; i <= 5; i++) cout << i << "\n"; return 0; }
- 1