洛谷 P5740 【深基7.例9】最厉害的学生 题解 C/C++

//P5740 【深基7.例9】最厉害的学生
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <sstream>
#define inf 0x3f3f3f3f
#define eps 1e-6
using namespace std;
#define clr(x) memset(x,0,sizeof((x)))
const int maxn = 1e5+1;//2e6+1
#define MAX(a,b,c) ((a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c)))
#define _max(a,b) ((a) > (b) ? (a) : (b))
#define _min(a,b) ((a) < (b) ? (a) : (b))
#define _for(a,b,c) for(int a = b;a<c;a++)

typedef struct student
{
	char name[10];
	int a,b,c,tot;
}stu;
/*
int cmp(const void* a,const void* b) {
	stu *s1 = (stu*)a;
	stu *s2 = (stu*)b;
	return (s1->tot) < (s2->tot);//从大到小
}
*/
bool cmp1( stu a, stu b) {
	return a.tot > b.tot;//从大到小
}

int main()
{
#ifdef LOCAL 
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);
#endif
	int n;
	stu s[1005];
	cin>>n;
	for(int i = 0;i<n;i++) {
		scanf("%s%d%d%d",s[i].name,&s[i].a,&s[i].b,&s[i].c);
		s[i].tot = s[i].a+s[i].b+s[i].c;
	}
	// qsort(s,n,sizeof(stu),cmp);
	sort(s,s+n,cmp1);
	printf("%s %d %d %d",s[0].name,s[0].a,s[0].b,s[0].c);

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值