青年歌手参加歌曲大赛,有5个评委对她进行打分,试编程求这位选手的平均得分(去掉一个最高分和一个最低分
青年歌手参加歌曲大赛,有5个评委对她进行打分,试编程求这位选手的平均得分(去掉一个最高分和一个最低分)...
青年歌手参加歌曲大赛,有5个评委对她进行打分,试编程求这位选手的平均得分(去掉一个最高分和一个最低分)
展开
1个回答
展开全部
//平台VC6.0
#include "stdafx.h"
#include <iostream>
#ifndef NUM_OF_JUDGE
#define NUM_OF_JUDGE 5
#endif
using std::cout;
void getResult(int* pDataInput, int nLength)
{
int* pScores = pDataInput;
int l_nMax = pScores[0];
int l_nMin = pScores[0];
for (int i = 0; i < nLength; i++)
{
if ( l_nMin > pScores[i])
{
l_nMin = pScores[i];
}
if (l_nMax < pScores[i])
{
l_nMax = pScores[i];
}
}
float l_nResult = 0;
for (int j = 0; j < nLength; j++)
{
l_nResult += pScores[j];
}
l_nResult = (l_nResult - l_nMin - l_nMax) / (nLength - 2);
cout<<"最后得分为:"<<l_nResult<<"\n";
}
int main(int argc, char* argv[])
{
cout<<"请输入"<<NUM_OF_JUDGE<<"位评委的打分:\n";
int* pScores = new int[NUM_OF_JUDGE];
for (int i = 0; i < NUM_OF_JUDGE; i++)
{
scanf("%d", pScores + i);
}
getResult(pScores, NUM_OF_JUDGE);
delete []pScores;
return 0;
}
#include "stdafx.h"
#include <iostream>
#ifndef NUM_OF_JUDGE
#define NUM_OF_JUDGE 5
#endif
using std::cout;
void getResult(int* pDataInput, int nLength)
{
int* pScores = pDataInput;
int l_nMax = pScores[0];
int l_nMin = pScores[0];
for (int i = 0; i < nLength; i++)
{
if ( l_nMin > pScores[i])
{
l_nMin = pScores[i];
}
if (l_nMax < pScores[i])
{
l_nMax = pScores[i];
}
}
float l_nResult = 0;
for (int j = 0; j < nLength; j++)
{
l_nResult += pScores[j];
}
l_nResult = (l_nResult - l_nMin - l_nMax) / (nLength - 2);
cout<<"最后得分为:"<<l_nResult<<"\n";
}
int main(int argc, char* argv[])
{
cout<<"请输入"<<NUM_OF_JUDGE<<"位评委的打分:\n";
int* pScores = new int[NUM_OF_JUDGE];
for (int i = 0; i < NUM_OF_JUDGE; i++)
{
scanf("%d", pScores + i);
}
getResult(pScores, NUM_OF_JUDGE);
delete []pScores;
return 0;
}
更多追问追答
追问
这是你写的?
还是上网搜的?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询