标签:华为入职练习 华为oj
#include "OJ.h" #include <iostream> using namespace std; /* 功能:对输入的整型数组,输出数组元素中的最大值、最大值的个数、最小值和最小值的个数 输入:int * pInputInteger:整型数组指针 int * InputNum:数组元素个数 输出:int * pMaxValue:数组中最大值 int * pMaxNum:数组中最大值的个数 int * pMinValue:数组中最小值 int * pMinNum:数组中最小值的个数 返回:void */ void OutputMaxAndMin(int * pInputInteger, int InputNum, int * pMaxValue, int * pMaxNum, int * pMinValue, int * pMinNum) { /*在这里实现功能*/ if (InputNum <= 0 || pInputInteger == NULL) { *pMaxNum =0; *pMinNum = 0; *pMaxValue = 0; *pMinValue = 0; return ; } *pMaxNum =1; *pMinNum = 1; *pMaxValue = pInputInteger[0]; *pMinValue = pInputInteger[0]; for (int i =1; i < InputNum; ++i) { if (pInputInteger[i] > *pMaxValue) { *pMaxValue = pInputInteger[i]; *pMaxNum = 1; } else if(pInputInteger[i] == *pMaxValue) { (*pMaxNum)++; } if (pInputInteger[i] < *pMinValue) { *pMinValue = pInputInteger[i]; *pMinNum = 1; } else if(pInputInteger[i] == *pMinValue) { (*pMinNum)++; } } return; } int main() { int aInputInteger[] = {1, 1,1,1,1,1,1}; int iMaxValue, iMaxNum, iMinValue, iMinNum; OutputMaxAndMin(aInputInteger, 0, &iMaxValue, &iMaxNum, &iMinValue, &iMinNum); cout<<iMaxNum<<" "<<iMaxValue<<endl; cout<<iMinNum<<" "<<iMinValue<<endl; return 0; }
标签:华为入职练习 华为oj
原文地址:http://blog.csdn.net/xiaohanstu/article/details/41926631