uva 10194 - Football (aka Soccer)

又是wa,有点搞不懂

  1 #include<iostream>
  2 #include<string>
  3 #include<vector>
  4 #include<algorithm>
  5 #include<stdlib.h>
  6 #include<stdio.h>
  7 using namespace std;
  8 typedef struct infoteam{
  9     string name;
 10     int games;
 11     int point;
 12     int win;
 13     int tie;
 14     int lose;
 15     int difference;
 16     int score;
 17     int against;
 18     infoteam(){
 19         games=0;
 20         win=0;
 21         tie=0;
 22         lose=0;
 23         score=0;
 24         against=0;
 25     }
 26     void getpoint(){
 27         point=3*win+tie;
 28     }
 29     void getdifference(){
 30         difference=score-against;
 31     }
 32 }infoteam;
 33 int cmp(const void *f1,const void* f2){
 34     infoteam* a=(infoteam*)f1;
 35     infoteam* b=(infoteam*)f2;
 36     if(a->point!=b->point)
 37         return b->point-a->point;
 38     if(a->win!=b->win)
 39         return b->win-a->win;
 40     if(a->difference!=b->difference)
 41         return b->difference-a->difference;
 42     if(a->score!=b->score)
 43         return b->score-a->score;
 44     if(a->games!=b->games)
 45         return a->games-b->games;
 46     return a->name>b->name;
 47 }
 48 int main(){
 49     int n;
 50     cin>>n;
 51     getchar();
 52     vector<string> v_teanname;
 53     while(n--){
 54         string s_gamename;
 55         getline(cin,s_gamename);
 56         int i_teamnum;
 57         cin>>i_teamnum;
 58         getchar();
 59         infoteam* str_info=new infoteam[i_teamnum];
 60         for(int i=0;i<i_teamnum;i++){
 61             string temp;
 62             getline(cin,temp);
 63             str_info[i].name=temp;
 64             //v_teanname.push_back(temp);
 65         }
 66         int i_gamenum;
 67         cin>>i_gamenum;
 68         getchar();
 69         while(i_gamenum--){
 70             string temp;
 71             getline(cin,temp);
 72             int start,middle,end,ateam,bteam;
 73             start=temp.find("#",0);
 74             for(int i=0;i<i_teamnum;i++){
 75                 if(str_info[i].name==temp.substr(0,start)){
 76                     ateam=i;
 77                     break;
 78                 }
 79             }
 80             middle=temp.find("@",0);
 81             end=temp.find("#",middle);
 82             for(int i=0;i<i_teamnum;i++){
 83                 if(str_info[i].name==temp.substr(end+1)){
 84                     bteam=i;
 85                     break;
 86                 }
 87             }
 88             int a=atoi(const_cast<char*>(temp.substr(start+1,middle).c_str()));
 89             int b=atoi(const_cast<char*>(temp.substr(middle+1,end).c_str()));
 90             str_info[ateam].score+=a;
 91             str_info[ateam].against+=b;
 92             str_info[bteam].score+=b;
 93             str_info[bteam].against+=a;
 94             str_info[ateam].games+=1;
 95             str_info[bteam].games+=1;
 96             if(a==b){
 97                 str_info[ateam].tie+=1;
 98                 str_info[bteam].tie+=1;
 99             }
100             else{
101                 (a>b)?(str_info[ateam].win+=1,str_info[bteam].lose+=1):(str_info[ateam].lose+=1,str_info[bteam].win+=1);
102             }
103         }
104         for(int i=0;i<i_teamnum;i++){
105             str_info[i].getdifference();
106             str_info[i].getpoint();
107         }    
108         qsort(str_info,i_teamnum,sizeof(infoteam),cmp);
109         cout<<s_gamename<<endl;
110         for(int i=0;i<i_teamnum;i++){
111             cout<<i+1<<") "<<str_info[i].name<<" "<<str_info[i].point<<"p, "<<
112                 str_info[i].games<<"g ("<<str_info[i].win<<"-"<<str_info[i].tie<<
113                 "-"<<str_info[i].lose<<"), "<<str_info[i].difference<<"gd ("<<
114                 str_info[i].score<<"-"<<str_info[i].against<<")"<<endl;
115         }
116         if(n!=0)
117             cout<<endl;
118         delete[] str_info;
119     }
120     //system("pause");
121 }

 

posted on 2013-12-31 10:42  云在心  阅读(196)  评论(0)    收藏  举报

导航