竞赛讨论区 > 求助D题 点进去看代码
头像
wyzhf99
编辑于 2021-03-15 21:31
+ 关注

求助D题 点进去看代码

#include<iostream>
#include<stdio.h>
#include<cmath>
#include<string>
#include<map>
#include<string.h>
#include<algorithm>

using namespace std;

const int N = 40;

int T,n,m;
struct node{
    string name;
    int points,wins,losses,draws,goals_scored,goals_allowed;
    int against;
}football[N];
int locate_name(string s){
    for(int i=1;i<=n;++i)
        if(s==football[i].name)
            return i;
    return -1;
}
bool cmp(node a,node b){
    if(a.points==b.points) {
        if (a.against == b.against) {
            if (a.goals_scored == b.goals_scored)
                return a.name > b.name;
            return a.goals_scored > b.goals_scored;
        }
        return a.against > b.against;
    }
    return a.points>b.points;
}
int main(){
    scanf("%d",&T);
    for(int k=1;k<=T;++k){
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;++i)
            cin>>football[i].name;
        string s1,s2;int socr1,socr2;
        while(m--){
            cin>>s1>>socr1>>s2>>socr2;
            football[locate_name(s1)].goals_scored+=socr1;
            football[locate_name(s2)].goals_scored+=socr2;
            football[locate_name(s1)].goals_allowed+=socr2;
            football[locate_name(s2)].goals_allowed+=socr1;
            if(socr1>socr2){
                football[locate_name(s1)].wins+=1;
                football[locate_name(s2)].losses+=1;
                football[locate_name(s1)].points+=3;
            }
            else if(socr1<socr2){
                football[locate_name(s2)].wins+=1;
                football[locate_name(s1)].losses+=1;
                football[locate_name(s2)].points+=3;
            }
            else{
                football[locate_name(s1)].draws+=1;
                football[locate_name(s2)].draws+=1;
                football[locate_name(s1)].points+=1;
                football[locate_name(s2)].points+=1;
            }
        }
        for(int i=1;i<=n;++i)
            football[i].against=football[i].goals_scored-football[i].goals_allowed;
        sort(football+1,football+n+1,cmp);
        cout<<"Group "<<k<<":"<<endl;
        for(int i=1;i<=n;++i)
            cout<<football[i].name<<' '<<football[i].points<<' '<<football[i].wins<<' '<<football[i].losses<<' '<<football[i].draws<<' '<<football[i].goals_scored<<' '<<football[i].goals_allowed<<endl;
        cout<<endl;
        //memset(football,0,sizeof(football));
        for(int i=1;i<=n;++i){
            football[i].name="";
            football[i].points=football[i].goals_allowed=football[i].goals_scored=football[i].draws=football[i].losses=football[i].wins=football[i].against=0;
        }
    }
    return 0;
}


求助大佬D题 感觉木有错啊 全部WA掉了 QAQ

全部评论

(1) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐