【算法笔记第6.9节 algorithm 】问题 A: 求最大最小数

版权声明:本文为博主原创文章,转载请注明出处 https://blog.csdn.net/xunalove/article/details/88377393

题目描述

先输入N,表示数的个数,然后输入N个数,求这N个数的最大值和最小值。N<=10000,输入的数的绝对值不大于10^6

样例输入

4  
2 0 1 2

样例输出

2 0

多组测试数组

#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int a[10010];
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        printf("%d %d\n", a[n-1], a[0]);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/xunalove/article/details/88377393
今日推荐