这种程序很简单的 如果真的是有能力的话 学业再忙 应该也花不了多少时间的
// uva 10194 Football (aka Soccer)
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
char temp[100];
int numOfTeam, numOfGame;
typedef struct
{
string name;
int point, gameInAll, wonGame, tiedGame, lostGame, goalDiff, goalScored, goalAgainst;
} TEAM;
TEAM t[31];
void init(int n)
{
for (int i=0; i<n; i++)
{
t[i].name = "";
t[i].point = 0;
t[i].gameInAll = 0;
t[i].wonGame = 0;
t[i].tiedGame = 0;
t[i].lostGame = 0;
t[i].goalScored = 0;
t[i].goalAgainst = 0;
t[i].goalDiff = 0;
}
}
int getTeamID(string str)
{
int i;
for ( i = 0 ; i < numOfTeam ; i++ )
if (str == t[i].name)
return i;
return 0;
}
void teamWin(string teamName1, string teamName2, int g1, int g2)
{
int team1, team2;
team1 = getTeamID(teamName1);
team2 = getTeamID(teamName2);
t[team1].point += 3;
t[team1].gameInAll++; t[team2].gameInAll++;
t[team1].wonGame++; t[team2].lostGame++;
t[team1].goalDiff += g1 - g2; t[team2].goalDiff += g2 - g1;
t[team1].goalScored += g1; t[team2].goalScored += g2;
t[team1].goalAgainst += g2; t[team2].goalAgainst += g1;
}
void teamTie(string teamName1, string teamName2, int g)
{
int team1, team2;
team1 = getTeamID(teamName1);
team2 = getTeamID(teamName2);
t[team1].point++; t[team2].point++;
t[team1].gameInAll++; t[team2].gameInAll++;
t[team1].tiedGame++; t[team2].tiedGame++;
t[team1].goalScored += g; t[team2].goalScored += g;
t[team1].goalAgainst += g; t[team2].goalAgainst += g;
}
int stringToInt(string str)
{
int sum = 0;
for (int i=0; i<str.length(); i++)
sum = sum*10 + str[i]-'0';
return sum;
}
void getcase()
{
int g1, g2;
string tn1, tn2;
cin.getline(temp,100); //read the tournament name;
cout << temp << endl;
cin.getline(temp,100); //read the team number;
numOfTeam = atoi(temp);
init(numOfTeam);
for (int i = 0 ; i < numOfTeam ; i++ )
{
cin.getline(temp,100); // read the team's name
t[i].name.append(temp);
}
cin.getline(temp,100); // read the number of games
numOfGame = atoi(temp);
for (int i = 0 ; i < numOfGame ; i++ )
{
cin.getline(temp,100); // read the result of game
string s = "";
s.append(temp);
tn1 = s.substr(0, s.find('#', 0));
g1 = stringToInt(s.substr(s.find('#', 0)+1, s.find('@', 0)-tn1.length()-1));
g2 = stringToInt(s.substr(s.find('@', 0)+1, s.find_last_of('#', s.length())-s.find('@', 0)-1));
tn2 = s.substr(s.find_last_of('#', s.length())+1);
if (g1 > g2)
teamWin(tn1, tn2, g1, g2);
else if (g2 > g1)
teamWin(tn2, tn1, g2, g1);
else
teamTie(tn1, tn2, g1);
}
}
void print()
{
for (int i = 0 ; i < numOfTeam ; i++ )
{
cout << i+1 << ") " << t[i].name << " " << t[i].point << "p, ";
cout << t[i].gameInAll << "g ";
cout << "(" << t[i].wonGame << "-" << t[i].tiedGame << "-" << t[i].lostGame << "), ";
cout << t[i].goalDiff << "gd ";
cout << "(" << t[i].goalScored << "-" << t[i].goalAgainst << ")" << endl;
}
}
int cmp(const void* e1, const void* e2)
{
const TEAM* t1 = (const TEAM* )e1;
const TEAM* t2 = (const TEAM* )e2;
if ( t1->point != t2->point ) return t2->point > t1->point;
if ( t1->wonGame != t2->wonGame ) return t2->wonGame > t1->wonGame;
if ( t1->goalDiff != t2->goalDiff ) return t2->goalDiff > t1->goalDiff;
if ( t1->goalScored != t2->goalScored ) return t2->goalScored > t1->goalScored;
if ( t1->gameInAll != t2->gameInAll ) return t1->gameInAll > t2->gameInAll;
string s1 = t1->name;
string s2 = t2->name;
for (int i=0; i<s1.length(); i++)
if (s1[i] <='Z' && s1[i] >='A')
s1[i] = s1[i]+32;
for (int i=0; i<s2.length(); i++)
if (s2[i] <='Z' && s2[i] >='A')
s2[i] = s2[i]+32;
return s1 > s2;
}
void slv()
{
qsort(&t, numOfTeam, sizeof(t[0]), cmp);
print();
}
int main()
{
bool flag = false;
int kase;
cin.getline(temp,100); //read the case number;
kase = atoi(temp);
while( kase-- )
{
if (flag)
cout << endl;
else
flag = true;
getcase();
slv();
}
return 0;
}