题解 | #求最大最小数#
求最大最小数
http://www.nowcoder.com/practice/82e5ff335eeb486aab359767895cc7b4
不需要排序,在读入的过程中维护好最大最小值就行了
#include <iostream>
using namespace std;
int main()
{
int n, tmp;
while (cin >> n)
{
int MAX = -0x3f3f3f3f, MIN = 0x3f3f3f3f;
for (int i = 0; i < n; ++i)
{
cin >> tmp;
if (tmp > MAX)
MAX = tmp;
if (tmp < MIN)
MIN = tmp;
}
cout << MAX << " " << MIN << endl;
}
return 0;
}