九度OJ-1483:求最大最小数

    xiaoxiao2021-03-25  76

    题目描述:

    输入N个(N<=10000)数字,求出这N个数字中的最大值和最小值。每个数字的绝对值不大于1000000。

    输入:

    输入包括多组测试用例,每组测试用例由一个整数N开头,接下去一行给出N个整数。

    输出:

    输出包括两个整数,为给定N个数中的最大值与最小值。

    样例输入: 5 1 2 3 4 5 3 3 7 8 样例输出: 5 1 8 3 来源: 2012年清华大学计算机研究生机试真题 #include <cstdio> #define MAXSIZE 10010 using namespace std; int main(){ int n; int buf[MAXSIZE]; int maxIndex,minIndex; while (scanf("%d",&n)!=EOF){ //initiate maxIndex=minIndex=0; //input &&search scanf("%d",&buf[0]); for (int i=1;i<n;i++){ scanf("%d",&buf[i]); if (buf[i]>buf[maxIndex]) maxIndex=i; if (buf[i]<buf[minIndex]) minIndex=i; } //output printf("%d %d\n",buf[maxIndex],buf[minIndex]); } return true; }

    转载请注明原文地址: https://ju.6miu.com/read-37543.html

    最新回复(0)