Problem H: 最大值和最小值

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:16 Solved:15

Description

找出n个数中的最大值和最小值

Input

第1行:输入一个整数n(n的取值范围是1~1000
第2行~第n+1行:输入n个整数(数的取值范围是-2147483648~2147483647)

Output

输出一行两个数,第一个是最大值,第二个是最小值

Sample Input Copy

5
2 3 100 -10 4

Sample Output Copy

100 -10

HINT

思路:这道题可以采用打擂台的方法
拓展:
求两个数中的较大值,我们可以利用模板库中的max函数
#include<bits/stdc++.h> //包含万能头文件 
using namespace std; //使用标准命名空间 
int main() //主函数,返回值的数据类型是整型 
{
  int a,b,ans;
  a=10;
  b=5;
  ans=max(a,b); //求两个数中的较大值
  cout<<ans;//输出的结果是10
  return 0; //返回0 
}

求两个数中的较小值,我们可以利用模板库中的min函数
#include<bits/stdc++.h> //包含万能头文件 
using namespace std; //使用标准命名空间 
int main() //主函数,返回值的数据类型是整型 
{
  int a,b,ans;
  a=10;
  b=5;
  ans=min(a,b); //求两个数中的较小值
  cout<<ans;//输出的结果是5
  return 0; //返回0 
}

Source/Category