Problem E: AB编程题--世界杯小组赛
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 93 Solved: 30
[ Submit][ Status][ Web Board]
Description
注:本题目自由设计,但必须使用类进行代码设计。
世界杯32支参赛队分为八个小组,每个小组分别有四支球队进行比赛,每支球队都必须和其他三支球队进行且只进行一场比赛,每组4个队循环比赛,共打6场(a1-a2;a1-a3;a1-a4;a2-a3;a2-a4;a3-a4),每场比赛90分钟,胜平负分别积3、1、0分。每个小组积分的前两名球队出线进入淘汰赛阶段的1/8决赛,共16支队,即“16强”。
每个小组分别有四只球队,其排名按以下规则确定:
a、积分高者排名靠前
b、小组中总净胜球高者排名靠前
c、小组中总进球数高者排名靠前
d、不能确定
净胜球数是指进球数(正数)与失球数(正数)的差。
如,红队胜黄队4:2,蓝队胜黄队3:1,红队负蓝队2:3
红队进6球,失5球,净胜球数为:6-5=1
黄队进3球,失7球,净胜球数为:3-7=-4
蓝队进6球,失3球,净胜球数为:6-3=3
//以下是可供参考的代码
#include
#include
#include
using namespace std;
class FootballGroup
{
private:
int score[4]; //总积分
int goaldiff[4]; //总净胜球
int totalgoals[4]; //总进球数
string teamname[4] ; //球队的名称
public:
FootballGroup()
{
for(int i=0; i<4; i++)
{
score[i]=goaldiff[i]=totalgoals[i]=0;
}
}
void setTeamName(int teamindex,string name) //设置第teamindex+1个队的队名
{
teamname[teamindex] = name;
}
void addMatchresult(int teamindex1,int teamindex2,int score1,int score2);
void showResult();
};
int main()
{
FootballGroup GroupA;
string name;
int i,j;
for(i=0; i<4; i++)
{
cin>>name;
GroupA.setTeamName(i,name); //球队a1,a2,a3,a4的名称
}
int score1,score2;
for(i=0; i<3; i++) //a1-a2;a1-a3;a1-a4;a2-a3;a2-a4;a3-a4
for(j=i+1; j<4; j++)
{
cin>>score1>>score2; //两队的比分
GroupA.addMatchresult(i,j,score1,score2);
}
GroupA.showResult();
return 0;
}
Input
第一行 4个参赛队伍的名称
第二行开始到第七行,6场比赛的比分(a1-a2;a1-a3;a1-a4;a2-a3;a2-a4;a3-a4)
Output
进入淘汰赛阶段的两只球队,如果不能确定,则输出"NO"
Sample Input
a1 a2 a3 a4
1 2
0 0
2 3
3 1
2 2
1 2
Sample Output
a2 a4
#include
#include
#include
using namespace std;
class FootballGroup
{
private:
int score[4]; //总积分
int goaldiff[4]; //总净胜球
int totalgoals[4]; //总进球数
string teamname[4] ; //球队的名称
public:
FootballGroup()
{
for(int i=0; i<4; i++)
{
score[i]=goaldiff[i]=totalgoals[i]=0;
}
}
void setTeamName(int teamindex,string name) //设置第teamindex+1个队的队名
{
teamname[teamindex] = name;
}
void addMatchresult(int teamindex1,int teamindex2,int score1,int score2);
friend void swap(int *s,int *ss,int *g,int *gg,int *t,int *tt,string *n,string *nn);
void showResult();
};
void FootballGroup::addMatchresult(int teamindex1,int teamindex2,int score1,int score2)
{
;
if(score1>score2)
{
score[teamindex1]+=3;
totalgoals[teamindex1]+=score1;
totalgoals[teamindex2]+=score2;
goaldiff[teamindex1]+=score1-score2;
}
else if(score1score[i])
swap(&score[i],&score[j],&goaldiff[i],&goaldiff[j],&totalgoals[i],&totalgoals[j],&teamname[i],&teamname[j]);
if(score[1]!=score[2])//第二三个队伍分数不一样
cout<goaldiff[i])
swap(&score[i],&score[j],&goaldiff[i],&goaldiff[j],&totalgoals[i],&totalgoals[j],&teamname[i],&teamname[j]);
}
if (goaldiff[1]!=goaldiff[2])
{
cout<totalgoals[2])
cout<goaldiff[i])
swap(&score[i],&score[j],&goaldiff[i],&goaldiff[j],&totalgoals[i],&totalgoals[j],&teamname[i],&teamname[j]);
}
if (goaldiff[1]!=goaldiff[2])
{
cout<totalgoals[2])
cout<totalgoals[i])
swap(&score[i],&score[j],&goaldiff[i],&goaldiff[j],&totalgoals[i],&totalgoals[j],&teamname[i],&teamname[j]);
}
if (totalgoals[1]!=totalgoals[2])
cout<goaldiff[i])
swap(&score[i],&score[j],&goaldiff[i],&goaldiff[j],&totalgoals[i],&totalgoals[j],&teamname[i],&teamname[j]);
}
if(goaldiff[1]!=goaldiff[2])
{
cout<totalgoals[2])
cout<totalgoals[i])
swap(&score[i],&score[j],&goaldiff[i],&goaldiff[j],&totalgoals[i],&totalgoals[j],&teamname[i],&teamname[j]);
}
if (totalgoals[1]!=totalgoals[2])
cout<totalgoals[i])
swap(&score[i],&score[j],&goaldiff[i],&goaldiff[j],&totalgoals[i],&totalgoals[j],&teamname[i],&teamname[j]);
}
if(totalgoals[0]!=totalgoals[1]&&totalgoals[1]!=totalgoals[2])
cout<totalgoals[i])
swap(&score[i],&score[j],&goaldiff[i],&goaldiff[j],&totalgoals[i],&totalgoals[j],&teamname[i],&teamname[j]);
}
if(totalgoals[1]!=totalgoals[2])
cout<>name;
GroupA.setTeamName(i,name); //球队a1,a2,a3,a4的名称
}
int score1,score2;
for(i=0; i<3; i++) //a1-a2;a1-a3;a1-a4;a2-a3;a2-a4;a3-a4
for(j=i+1; j<4; j++)
{
cin>>score1>>score2; //两队的比分
GroupA.addMatchresult(i,j,score1,score2);
}
GroupA.showResult();
return 0;
}