Total Submission(s): 14 Accepted Submission(s): 3
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.
Process to the end of file.
Output a blank line after each test case.
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
Manchester 8 Portsmouth 5 Liverpool 2
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; }