Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 134 Solved: 25
[Submit][Status][Web Board]
Description
五个人去面试,他们之前已经经历5次考试,请你帮助面试官按之前的平均成绩初步筛选。
Input
人名(空格)考试成绩(空格间隔)(五个人为五行)
Output
“Name:”人名(换行)“平均成绩:”成绩(若为浮点数则保留1位小数)(五个人为十行)(引号内部须打出)
Sample Input
pjs 100 100 100 100 90
zp 2 2 2 2 10
yzh 20 34 23 10 5
dwr 3 4 5 6 7
zcq 50 60 70 80 90
Sample Output
Name:pjs
平均成绩:98
Name:zcq
平均成绩:70
Name:yzh
平均成绩:18.4
Name:dwr
平均成绩:5
Name:zp
平均成绩:3.6
C++/*代码*/
#include <iostream>
using namespace std;
#include <string>
#include <iomanip>
struct Score{
int score;
};
struct people{
string name;
int sum;
double aa;
struct Score sarray[5];
};
void cinpeople(struct people parray[],int len)
{
for(int i=0;i<len;i++)
{
parray[i].sum=0;
cin>>parray[i].name;
for(int j=0;j<len;j++)
{
cin>>parray[i].sarray[j].score;
parray[i].sum+=parray[i].sarray[j].score;
}
parray[i].aa=parray[i].sum*1.0/len;
}
}
void print(struct people parray[],int len)
{
struct people temp;
for(int i=0;i<len-1;i++)
{
for(int j=i+1;j<len;j++)
{
if(parray[j].aa>parray[i].aa)
{
temp=parray[j];
parray[j]=parray[i];
parray[i]=temp;
}
}
}
for(int i=0;i<5;i++)
{
cout<<"Name:"<<parray[i].name<<endl;
if(((int)(parray[i].aa*10)%10)==0)
cout<<"平均成绩:"<<setiosflags(ios::fixed)<<setprecision(0)<<parray[i].aa<<endl;
else
cout<<"平均成绩:"<<setiosflags(ios::fixed)<<setprecision(1)<<parray[i].aa<<endl;
}
}
int main()
{
struct people parray[5];
int len=sizeof(parray)/sizeof(parray[0]);
cinpeople(parray,len);
print(parray,len);
return 0;
}