思路:用sort函数按每个队伍的penalty points 和 Slove 进行排序,输出解决最多的,并且penalty points 最小的
代码如下:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
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;
}