코딩도사의 코드정리

soccer UVA 본문

컴퓨터 이야기/C++

soccer UVA

코딩도사 2011. 1. 7. 01:38
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <limits>
#include <ctime>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
using namespace std;

#ifdef mycom
ifstream fin("input");
#else
#define fin cin
#endif

class team
{
public:
 int score;
 int wincounter;
 int goaldiff;
 int manygoal;
 int gamecounter;
 string teamname;

 ////////////
 int drawcounter;
 int losecounter;
 int sibalgoal;
 team() { 
  score = 0;
  wincounter = 0;
  goaldiff = 0;
  manygoal = 0;
  gamecounter = 0;
  drawcounter=0;
  losecounter=0;
  sibalgoal=0;
 }
 
 bool operator<(const team& t) const
 {
  if(this->score == t.score)
  {
   if(this->wincounter == t.wincounter)
   {
    if(this->goaldiff == t.goaldiff)
    {
     if(this->manygoal == t.manygoal)
     {
      if(this->gamecounter == t.gamecounter)
      {
       char ateam[100];
       char bteam[100];
       strcpy(ateam, teamname.c_str());
       strcpy(bteam, t.teamname.c_str());
       for(int i=0; i<strlen(ateam); i++)
        ateam[i] = toupper(ateam[i]);
       for(int i=0; i<strlen(bteam); i++)
        bteam[i] = toupper(bteam[i]);
       string a = ateam;
       string b = bteam;
       return a > b;
      }
      else
      {
       return this->gamecounter > t.gamecounter;
      }
     }
     else
     {
      return this->manygoal < t.manygoal;
     }
    }
    else
    {
     return this->goaldiff < t.goaldiff;
    }
   }
   else
   {
    return this->wincounter < t.wincounter;
   }
  }
  else
  {
   return this->score < t.score;
  }
 }
};


int main()
{
 int N;
 
 fin >> N;
 fin.ignore(1024, '\n');
 for(int n=1; n<=N; n++)
 {
  int T;
  
  string tonorname;
  char temptonorname[1024];
  
  fin.getline(temptonorname, 1024);
  tonorname = temptonorname;
  fin >> T;
  fin.ignore(1024, '\n');
  vector<team> teams;
  for(int j=1; j<=T; j++)
  {
   char temp[1024];
   fin.getline(temp, 1024);
   team tempteam;
   tempteam.teamname = temp;
   teams.push_back(tempteam);
  }

  int G;
  fin >> G;
  fin.ignore(1024, '\n');
  for(int g=1; g<=G; g++)
  {
   char temp[1024];
   char* p;
   
   int Ascore, Bscore;
   string Aname;
   string Bname;
   fin.getline(temp, 1024);
   p = strtok(temp, "#");
   Aname = p;
   p = strtok(0, "@");
   Ascore = atoi(p);
   p = strtok(0, "#");
   Bscore = atoi(p);
   p = strtok(0, "#");
   Bname = p;
   for(vector<team>::iterator iter = teams.begin(); iter != teams.end(); ++iter)
   {
    if((*iter).teamname == Aname)
    {
     if(Ascore > Bscore)
     {
      iter->score += 3;
      iter->wincounter++;
     }
     else if(Ascore == Bscore)
     {
      iter->drawcounter++;
      iter->score += 1;
     }
     else
      iter->losecounter++;
     iter->sibalgoal += Bscore;
     iter->manygoal += Ascore;
     iter->gamecounter++;
     iter->goaldiff += Ascore - Bscore;
    }
    else if( (*iter).teamname == Bname)
    {
     if(Bscore > Ascore)
     {
      iter->score += 3;
      iter->wincounter++;
     }
     else if(Ascore == Bscore)
     {
      iter->score += 1;
      iter->drawcounter++;
     }
     else
      iter->losecounter++;
     iter->sibalgoal += Ascore;
     iter->manygoal += Bscore;
     iter->gamecounter++;
     iter->goaldiff += Bscore - Ascore;
    }
   }

  }
  sort(teams.rbegin(), teams.rend());
  cout << tonorname << endl;
  for(int i = 0; i<teams.size(); i++)
  {
   printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", 
    i+1,
    teams[i].teamname.c_str(),
    teams[i].score,
    teams[i].gamecounter, 
    teams[i].wincounter,
    teams[i].drawcounter,
    teams[i].losecounter,
    teams[i].goaldiff,
    teams[i].manygoal,
    teams[i].sibalgoal);
  }
  if(n != N)
   cout << endl;
 }
 return 0;
}


'컴퓨터 이야기 > C++' 카테고리의 다른 글

순열  (0) 2011.01.07
부분집합  (0) 2011.01.07
Bridge  (0) 2011.01.05
Vito's Family  (0) 2011.01.02
Erdos Numbers  (0) 2011.01.01