文章

55

粉丝

57

获赞

11

访问

10.4k

头像
学生成绩管理 题解:C++
P1052
发布于2024年3月24日 14:39
阅读数 97

#include <iostream>
#include<string>
using namespace std;

struct student{
	string id;
	string banji;
	string name;
	float score[3];
};

int main(){
	int n;
	struct student stu[100];
	cin>>n;
	for(int i = 0; i<n; i++){
		cin>>stu[i].id>>stu[i].banji>>stu[i].name;
		for(int j = 0; j<3; j++){
			cin>>stu[i].score[j];
		}
	}
	struct student max = stu[0];
	float da = 0;
	for(int i = 0; i<n; i++){
		float sum =0;
		for(int j = 0; j<3; j++){
			sum+=stu[i].score[j];
		}
		float avs = sum/3.0;
		if(avs > (max.score[0]+max.score[1]+max.score[2])/3.0){
			max = stu[i];
			da = avs;
		}
		printf("%s %.1f\n",stu[i].name.c_str(),avs);
	}
	cout<<max.id<<" "<<max.banji<<" "<<max.name<<" ";
	printf("%.1f %.1f %.1f %.1f",max.score[0],max.score[1],max.score[2],da);
}
 
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发