题意:求出晋级的队伍,并按字典序输出,排序要求是:1.按得分降序,2.按赢球和输球的差的降序,3,按赢的降序,麻烦的是储存数据
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int MAXN = 200;
char Map[MAXN][MAXN];
struct node{
int goal;
int equal;
int defeat;
int mark;
int sign;
}arr[MAXN];
int n,cnt;
map<string,int>ans;
map<int,string>bns;
int cmp(node a,node b){
if (a.mark > b.mark)
return 1;
else if (a.mark < b.mark)
return 0;
else if (a.goal-a.defeat > b.goal-b.defeat)
return 1;
else if (a.goal-a.defeat < b.goal-b.defeat)
return 0;
else return a.goal > b.goal;
}
int cmp1(node a,node b){
return bns[a.sign] < bns[b.sign];
}
int main(){
char str[MAXN];
string ch;
int cnt = 0;
memset(arr,0,sizeof(arr));
scanf("%d%*c",&n);
for (int i = 0; i < n; i++){
cin >> ch;
ans[ch] = i;
bns[i] = ch;
arr[i].sign = i;
}
for (int i = 0; i < n*(n-1)/2; i++){
string a,b;
int c,d;
cin >> ch;
a = b = ch;
for (int i = 0; i < ch.length(); i++)
if (ch[i] == '-'){
a.erase(a.begin()+i,a.end());
b.erase(b.begin(),b.begin()+i+1);
}
scanf("%s",str);
sscanf(str,"%d:%d",&c,&d);
if (c > d){
arr[ans[a]].mark += 3;
arr[ans[a]].goal += c;
arr[ans[a]].defeat += d;
arr[ans[b]].goal += d;
arr[ans[b]].defeat += c;
}
else if (c < d) {
arr[ans[b]].mark += 3;
arr[ans[b]].goal += d;
arr[ans[b]].defeat += c;
arr[ans[a]].goal += c;
arr[ans[a]].defeat += d;
}
else {
arr[ans[a]].mark += 1;
arr[ans[a]].goal += c;
arr[ans[a]].defeat += d;
arr[ans[b]].mark += 1;
arr[ans[b]].goal += d;
arr[ans[b]].defeat += c;
}
}
sort(arr,arr+n,cmp);
sort(arr,arr+n/2,cmp1);
for (int i = 0; i < n/2; i++)
cout << bns[arr[i].sign] << endl;
return 0;
}