zoukankan      html  css  js  c++  java
  • HDU Football Score

    Football Score

    Time Limit: 1000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 14    Accepted Submission(s): 3
    Problem Description
    Football is one of the greatest games in the world. Lots of people like to play football. After one season of matches, the header has to calculate the last scores of every team. He is too lazy that he doesn't want to calculate, so he asks you to write a program for him to solve the problem.

    Here are the rules:
    1 Every team has to match with all the other teams.
    2 Every two teams have to match for two times,one at home and one away.
    3 In one match, the winner will get 3 points, the loser will get 0 point. If it is draw, both of them will get 1 point.
     
    Input
    The input consists of many test cases. In each case, there will be a number N in the first line which means the number of teams. Followed by N * (N – 1)lines. Each line stands for a match between two teams. The format is: "Team1 VS Team2 p:q", p stands for the balls that Team1 has kicked in and q stands for the balls that Team2 has kicked in. p and q are not greater than 9.

    Process to the end of file.
     
    Output
    For each test case, output the teams and their scores in descending order. One line a team, the format is: "TeamX scores". If two teams get the same score, the one with high net goals will be ahead, which net goal means the difference between the total balls that the team kicked in and the total balls that the team lost. IE: if one team kicked in 30 balls and lost 40 balls, then the net goal is 30 – 40 = -10. If two teams have the same score and the same net goal, the one whose kicked in balls is bigger will be ahead. If two teams have the same score and the same net goal and the same kicked in balls, they will be outputed in alphabetic order.

    Output a blank line after each test case.
     
    SampleInput
    3
    Manchester VS Portsmouth 3:0
    Liverpool VS Manchester 1:1
    Liverpool VS Portsmouth 0:0
    Portsmouth VS Manchester 1:1
    Manchester VS Liverpool 2:1
    Liverpool VS Portsmouth 1:2
     
    SampleOutput
    Manchester 8
    Portsmouth 5
    Liverpool 2
    Hint
    Hint
    Huge input, scanf is recommended.
     
    #include<iostream>
    #include<map>
    #include<set>
    #include<algorithm>
    #include<cstdio>
    #include<string>
    
    using namespace std;
    
    struct Node{
        string name;
        int score;
        int in,out;
    
        bool operator < (const Node &a) const{
            if(a.score!=score)
                return a.score<score;
            else if((a.in-a.out)!=(in-out))
                return (a.in-a.out)<(in-out);
            else if(a.in!=in)
                return a.in<in;
            else
                return name<a.name;
        }
    }node;
    
    map<string,Node> List;
    set<Node> Out;
    char str1[1000],str2[1000];
    string s1,s2;
    int a,b;
    
    int main(){
    
        //freopen("input.txt","r",stdin);
    
        int n;
        while(scanf("%d",&n)!=EOF){
            List.clear();
            Out.clear();
            for(int i=0;i<n*(n-1);i++){
                scanf("%s VS %s %d:%d",str1,str2,&a,&b);
                s1=string(str1);
                s2=string(str2);
                node.name=s1;node.score=(a==b?1:(a>b?3:0));node.in=a;node.out=b;
                if(List.count(s1)){
                    List[s1].score+=node.score;List[s1].in+=node.in;List[s1].out+=node.out;
                }else{
                    List.insert(make_pair(s1,node));
                }
    
                node.name=s2;node.score=(a==b?1:(a<b?3:0));node.in=b;node.out=a;
                if(List.count(s2)){
                    List[s2].score+=node.score;List[s2].in+=node.in;List[s2].out+=node.out;
                }else{
                    List.insert(make_pair(s2,node));
                }
            }
            map<string,Node>::iterator it;
            for(it=List.begin();it!=List.end();it++)
                Out.insert(it->second);
            set<Node>::iterator it2;
            for(it2=Out.begin();it2!=Out.end();it2++)
                cout<<(it2->name).c_str()<<" "<<it2->score<<endl;
            cout<<endl;
        }
        return 0;
    }
     
     
     
  • 相关阅读:
    Jmeter监控服务器性能
    三种主流的WebService实现方案(REST/SOAP/XML-RPC)简述及比较
    从0到1搭建移动App功能自动化测试平台(0):背景介绍和平台规划
    Jmeter监控系统等资源,ServerAgent端口的修改
    Performance plugin离线安装
    Oracle定义常量和变量
    通过FTP将一个数据文件从A服务器下载到B服务器的整个过程
    Oracle使用%rowtype变量存储一行数据
    Oracle使用%type类型的变量输出结果
    mdf与ldf文件如何还原到SQLserver数据库
  • 原文地址:https://www.cnblogs.com/jackge/p/2969919.html
Copyright © 2011-2022 走看看