题目描述
输入N个(N<=10000)数字,求出这N个数字中的最大值和最小值。每个数字的绝对值不大于1000000。
输入描述:
输入包括多组测试用例,每组测试用例由一个整数N开头,接下去一行给出N个整数。
输出描述:
输出包括两个整数,为给定N个数中的最大值与最小值。
示例1
输入
5
1 2 3 4 5
3
3 7 8
输出
5 1
8 3
题目解析:很简单,将数据排个序就行了,使用sort就行,或者自己用循环排一下找最大和最小
代码:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
#include<vector>
using namespace std;
int main(){
int count,number;
vector<int> vc;
while(cin >> count){
for(int i = 1;i <= count;i++){
cin >> number;
vc.push_back(number);
}
int len = vc.size() - 1;
sort(vc.begin(),vc.end());
cout << vc[len] << endl;
cout << vc[0] << endl;
vc.clear(); //消除上次数据
}
return 0;
}