1 条题解
-
0
练53.1 打擂台
解题思路
读10个数,维护其中最大值,按样例加上“最大的数:”输出。
正确性说明
按顺序完成所述运算后,每个输入元素都被处理在相应位置或统计项中。保存的中间状态与已处理数据对应,最终输出与题目定义一致。
易错点
虽然输入说明称整数,样例出现91.5,使用double兼容。
复杂度
时间O(1),空间O(1)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); double best = -numeric_limits<double>::infinity(); for (int i = 0; i < 10; i++) { double x; cin >> x; best = max(best, x); } cout << "最大的数:" << best << "\n"; return 0; }
- 1