# a contesting decision(sort 函数 解决按结构体成员排序)

2018-03-07 02:49:46         来源：摆渡人的博客

```#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct ss
{
char name[20];
int p1s, p1t, p2s, p2t, p3s, p3t, p4s, p4t;
int pp;
int slove;
}team[50];
bool cmp(struct ss a, struct ss b)
{
if (a.slove == b.slove)
return a.pp < b.pp;
else
return a.slove > b.slove;
}
int main()
{
int t;
int x;

cin >> t;
x = 0;

while (t--)
{
scanf("%s%d%d%d%d%d%d%d%d", team[x].name, &team[x].p1s, &team[x].p1t, &team[x].p2s, &team[x].p2t, &team[x].p3s, &team[x].p3t, &team[x].p4s, &team[x].p4t );
if (team[x].p1t)
{
team[x].pp+= (team[x].p1s - 1) * 20 + team[x].p1t;
team[x].slove++;
}
if (team[x].p2t)
{
team[x].pp += (team[x].p2s - 1) * 20 + team[x].p2t;
team[x].slove++;
}
if (team[x].p3t)
{
team[x].pp += (team[x].p3s - 1) * 20 + team[x].p3t;
team[x].slove++;
}
if (team[x].p4t)
{
team[x].pp += (team[x].p4s - 1) * 20 + team[x].p4t;
team[x].slove++;
}
x++;
}
sort(team, team + x, cmp);
printf("%s %d %d\n", team[0].name, team[0].slove, team[0].pp);

system("pause");
return 0;
}```