codevs1201 最小数和最大数

题目描述 Description
输入n个数,n<=100,找到其中最小的数和最大的数

输入描述 Input Description
第一行一个整数n

接下来一行n个整数,每个整数不超过231 -1

输出描述 Output Description
最小和最大的数

样例输入 Sample Input
4

1 2 3 4

样例输出 Sample Output
1 4

数据范围及提示 Data Size & Hint


#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
  int n,a[105],i,mx=0x7fffffff,mn=0x80000000;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    mx=min(mx,a[i]); mn=max(mn,a[i]);
  }
  printf("%d %d ",mx,mn);
  return 0;
}

原文地址:https://www.cnblogs.com/codetogether/p/7064495.html