Pir Zöhre Ana Forum

Tam Versiyon: La-Liga 2006-2007
Şu anda arşiv modunu görüntülemektesiniz. Tam versiyonu görüntülemek için buraya tıklayınız.
Mac sonuçları dosyasını okuyarak Puan Tablosu yazdırma

#include <typeinfo>
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;


struct SFootBallTeam
{
string name ;
int point;
int wins;
int ties;
int loses;
int goalScored;
int goalHad;
};

typedef struct SFootBallTeam FootBallTeam;

struct SMatch {
string home ;
string visitor;
int scored;
int away;
} ;

typedef struct SMatch Match;


bool loadFromFile(Match *array,int &length,const string &fileName){
Match mt;
length=0;
std::ifstream ifile;
ifile.open(fileName.c_str());
if (ifile.fail()) return false;
while (!ifile.eof()){
ifile >> mt.home >> mt.scored >> mt.visitor >> mt.away ;
if (ifile.eof()) break;
array[length++]=mt;
}
ifile.close();
return true;
}


int main(int argc, char* argv[])
{
if (argc<2){
cout << "Usage:" << endl ;
cout << argv[0] << " input" << endl ;
exit(0);
}
string fileName = argv[1] ;
Match leaguge[1024];
int numberOfMatch=0;
loadFromFile(leaguge,numberOfMatch,fileName);
FootBallTeam teams[36];
int numberOfTeams=0;


int i=1,j=0;
int temp_numberofmatch;
FootBallTeam temp_team[1000];
string team_name;


for(i=1;i<=numberOfMatch;i++)
{
temp_team[j++].name=leaguge[i].home; temp_team[j++].name=leaguge[i].away; }

temp_numberofmatch=j;

for(i=1;i<=temp_numberofmatch-1;i++)
{
team_name=temp_team[i].name;
for(j=i+1;j<=temp_numberofmatch;j++) /* "i" will turn until temp_numberofmatch-1 */
{
if(team_name==temp_team[j].name) {
temp_team[j].name="XXX";
}
}
}

j=0;
for(i=1;i<=temp_numberofmatch;i++)
{
if(temp_team[i].name!="XXX")
{
teams[j++].name=temp_team[i].name;
}
}
numberOfTeams=j;

/* Now we will turn i and j , and then
determine the table according to results */

for(i=1;i<=numberOfTeams;i++)
{
for(j=1;j<=numberOfMatch;j++)
{
if(teams[i].name==leaguge[j].home)
{
if(leaguge[j].scored<leaguge[j].away)
{
teams[i].point+=0; // Do not change home team point
teams[i].loses++; // add +1 lose to home team
teams[i].goalScored+=leaguge[j].scored; // Number of goals that home team scored
teams[i].goalHad+=leaguge[j].away; // Number of goals that home team had
}
if(leaguge[j].scored==leaguge[j].away)
{
teams[i].point+=1; // add +1 point to both teams
teams[i].ties++; // add +1 ties to both teams
teams[i].goalScored+=leaguge[j].scored; // Number of goals that each teams scored
teams[i].goalHad+=leaguge[j].away; // Number of goals that each teams had
}
if(leaguge[j].scored>leaguge[j].away)
{
teams[i].point+=3; // add +3 point to home team
teams[i].wins++; // add +1 win to home team
teams[i].goalScored+=leaguge[j].scored; // Number of goals that home team scored
teams[i].goalHad+=leaguge[j].away; // Number of goals that home team had
}
}
if(teams[i].name==leaguge[j].visitor)
{
if(leaguge[j].away<leaguge[j].scored)
{
teams[i].point+=0; // Do not change home team's point
teams[i].loses++; // add +1 lose to away team
teams[i].goalScored+=leaguge[j].scored; // Number of goals that away team scored
teams[i].goalHad+=leaguge[j].away; // Numver of goals that away team had
}
if(leaguge[j].away==leaguge[j].scored)
{
teams[i].point+=1;
teams[i].ties++;
teams[i].goalScored+=leaguge[j].scored;
teams[i].goalHad+=leaguge[j].away;
}
if(leaguge[j].away>leaguge[j].scored) // Away team wins
{
teams[i].point+=3; // Same formulas with the case away team wins
teams[i].wins++;
teams[i].goalScored+=leaguge[j].scored;
teams[i].goalHad+=leaguge[j].away;
}
}

}
}

int puan; string takim;
int kazan;
int kayip;
int berabere;
int attigi;
int yedigi;

for(i=1;i<=numberOfTeams-1;i++) {
for(j=1;j<=numberOfTeams-i;j++)
{
if(teams[j].point<teams[j+1].point) {
puan=teams[j].point;

takim=teams[j].name;
kazan=teams[j].wins;
kayip=teams[j].loses;
berabere=teams[j].ties;
attigi=teams[j].goalScored;
yedigi=teams[j].goalHad;
teams[j].point=teams[j+1].point;

teams[j].name=teams[j+1].name;
teams[j].wins=teams[j+1].wins;
teams[j].loses=teams[j+1].loses;
teams[j].ties=teams[j+1].ties;
teams[j].goalScored=teams[j+1].goalScored;
teams[j].goalHad=teams[j+1].goalHad;

teams[j+1].point=puan;

teams[j+1].name=takim;
teams[j+1].wins=kazan;
teams[j+1].loses=kayip;
teams[j+1].ties=berabere;
teams[j+1].goalScored=attigi;
teams[j+1].goalHad=yedigi; // here it has been swapped


}
}
}

FootBallTeam club;

for(i=1;i<=numberOfTeams-1;i++) {
if(teams[i].point==teams[i+1].point) {
if(((teams[i].goalScored-teams[i].goalHad)-(teams[i+1].goalScored-teams[i+1].goalHad))<0) {
club=teams[i];
teams[i]=teams[i+1];
teams[i+1]=club;
}
}

/* This is the case : ith team and (i+1)th team has equal points and equal averages */


if((teams[i].point==teams[i+1].point)&&((teams[i].goalScored-teams[i].goalHad)==(teams[i+1].goalScored-teams[i+1].goalHad)))
{
if(teams[i].name>teams[i+1].name)
{
club=teams[i];
teams[i]=teams[i+1];
teams[i+1]=club;
}
}
}

/* Here is the format of the table */

cout << "POS. NAME PLAYED WIN DRAWN LOST FOR AGAINST GD POINTS" << endl ;
for(int i=0;i<numberOfTeams;i++){
FootBallTeam tm= teams[i];
cout<<setw(5)<< (i+1); //position of team
cout<<setw(17)<<tm.name; //name of the team
cout<<setw(8)<<tm.wins+tm.ties+tm.loses; //# of
cout<<setw(5)<<tm.wins; //# of wins
cout<<setw(7)<<tm.ties; //# of draws
cout<<setw(6)<<tm.loses; //# of losses
cout<<setw(5)<<tm.goalScored; //# of goals scored
cout<<setw(8)<<tm.goalHad;//# of goals scored against
cout<<setw(4)<<tm.goalScored-tm.goalHad; //goal
cout<<setw(8)<<tm.point<<endl;
}
return 0;
}