洛谷-P1051 谁拿了最多奖学金-题解

【洛谷】P1051 谁拿了最多奖学金 【题解】

这一题呢由于输入数据非常多,所以我们需要用到struct结构体来解题~,由于奖学金的种类很多,所以代码也比较长,大家忍受一下!
蒟蒻打的手都酸了
这一题我们需要注意,这些奖学金是可以叠加的,所以当第一个奖学金判断完后,后面的判断不能用else if,还是要用if,不然很无辜的几位同学就会莫名其妙的少掉一堆奖学金了!
上代码!注:我命名太长了,写得惨不忍睹 ,大家谅解一下~

#include<iostream>
#include<algorithm>
using namespace std;
struct student{
	string name;
	int averageScore;
	int deliberatingScore;
	char studentCadres;
	char westStudent;
	int papersNumber;
	int money;
	int serialNumber;
};
bool cmp(student a,student b){
	if(a.money==b.money)
		return a.serialNumber<b.serialNumber;
	return a.money>b.money;
}
int main(){
	student student[1001];
	int n,num=0;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>student[i].name;
		cin>>student[i].averageScore;
		cin>>student[i].deliberatingScore;
		cin>>student[i].studentCadres;
		cin>>student[i].westStudent;
		cin>>student[i].papersNumber;
		student[i].serialNumber=i;
		student[i].money=0;
		if(student[i].averageScore>80&&student[i].papersNumber>0)
			student[i].money+=8000;
		if(student[i].averageScore>85&&student[i].deliberatingScore>80)
			student[i].money+=4000;
		if(student[i].averageScore>90)
			student[i].money+=2000;
		if(student[i].westStudent=='Y'&&student[i].averageScore>85)
			student[i].money+=1000;
		if(student[i].studentCadres=='Y'&&student[i].deliberatingScore>80)
			student[i].money+=850; 
		num+=student[i].money;
	}sort(student+1,student+n,cmp);
	cout<<student[1].name<<endl<<student[1].money<<endl<<num;
	return 0;
}

这一题毕竟是结构体排序,而且代码本来就很长,所以这里用了sort排序,如果用冒泡和选择的话,代码就更惨不忍睹了~
对了,最后提醒大家,结构体排序如果用sort,一定要写cmp!
end~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值