| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1961 人关注过本帖
标题:[求助]ACM10194: Football (aka Soccer)
只看楼主 加入收藏
yelo20053533
Rank: 1
等 级:新手上路
帖 子:161
专家分:0
注 册:2006-11-27
收藏
得分:0 
呼唤孔明先生
2006-12-12 12:08
yelo20053533
Rank: 1
等 级:新手上路
帖 子:161
专家分:0
注 册:2006-11-27
收藏
得分:0 
大家加油
2006-12-13 17:26
yelo20053533
Rank: 1
等 级:新手上路
帖 子:161
专家分:0
注 册:2006-11-27
收藏
得分:0 
加油
2006-12-15 13:08
yelo20053533
Rank: 1
等 级:新手上路
帖 子:161
专家分:0
注 册:2006-11-27
收藏
得分:0 
求助
2006-12-16 09:50
卧龙孔明
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:59
帖 子:3872
专家分:684
注 册:2006-10-13
收藏
得分:0 
按照我在6楼写的思路与算法思想做就行,应该是可行的,你最好先自己写,如果有什么问题将你写的程序帖出来,我们会帮助你修改或提供建议.

毕竟自己多实践才是提高的捷径.

我本意是帮助你写的,但我也是学生且本程序较长,学业较忙,很难抽出时间与精力来写这样的程序.

My Blog: www.aiexp.info
虽然我的路是从这里开始的,但是这里不再是乐土.感谢曾经影响过,引导过,帮助过我的董凯,飞燕,leeco,starwing,Rockcarry,soft_wind等等等等.别了,BCCN.
2006-12-16 17:53
sjn819
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-7-31
收藏
得分:0 
这种程序很简单的 如果真的是有能力的话 学业再忙 应该也花不了多少时间的
// 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;
}
2007-08-09 09:31
快速回复:[求助]ACM10194: Football (aka Soccer)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036155 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved