2615: AB编程题--世界杯小组赛

时间限制: 1 Sec  内存限制: 128 MB

提交: 100  解决: 35

题目描述

注:本题目自由设计,但必须使用类进行代码设计。

世界杯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 <stdio.h>

#include <iostream>

#include <string>

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;

}

输入

第一行 4个参赛队伍的名称

第二行开始到第七行,6场比赛的比分(a1-a2;a1-a3;a1-a4;a2-a3;a2-a4;a3-a4)

输出

进入淘汰赛阶段的两只球队,如果不能确定,则输出"NO"

样例输入

a1 a2 a3 a4
1 2
0 0
2 3
3 1
2 2
1 2

样例输出

a2 a4

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

#include <stdio.h>
#include <iostream>
#include <cstring>
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();
};
void FootballGroup::addMatchresult(int teamindex1,int teamindex2,int score1,int score2)
{
if(score1>score2)
{
score[teamindex1]+=3;
goaldiff[teamindex1]+=score1-score2;
goaldiff[teamindex2]+=score2-score1;
totalgoals[teamindex1]+=score1;
totalgoals[teamindex2]+=score2;
}
else if(score1<score2)
{
score[teamindex2]+=3;
goaldiff[teamindex1]+=score1-score2;
goaldiff[teamindex2]+=score2-score1;
totalgoals[teamindex1]+=score1;
totalgoals[teamindex2]+=score2;
}
else
{
score[teamindex1]+=1;
totalgoals[teamindex1]+=score1;
score[teamindex2]+=1;
totalgoals[teamindex2]+=score2;
}
}
void FootballGroup::showResult()
{
int i,j,t1,t2,t3;
string c;
for(i=0; i<3; i++)
for(j=i+1; j<4; j++)
{
if(score[j]>score[i])
{
t1=score[i];
score[i]=score[j];
score[j]=t1;
t2=goaldiff[i];
goaldiff[i]=goaldiff[j];
goaldiff[j]=t2;
t3=totalgoals[i];
totalgoals[i]=totalgoals[j];
totalgoals[j]=t3;
c=teamname[i];
teamname[i]=teamname[j];
teamname[j]=c;
}
}
if(score[1]!=score[2])
cout<<teamname[0]<<" "<<teamname[1]<<endl;
else if (score[0]!=score[1]&&score[1]==score[2]&&score[2]!=score[3])
{
for(i=1; i<2; i++)
for(j=i+1; j<3; j++)
{
if(goaldiff[j]>goaldiff[i])
{
t1=score[i];
score[i]=score[j];
score[j]=t1;
t2=goaldiff[i];
goaldiff[i]=goaldiff[j];
goaldiff[j]=t2;
t3=totalgoals[i];
totalgoals[i]=totalgoals[j];
totalgoals[j]=t3;
c=teamname[i];
teamname[i]=teamname[j];
teamname[j]=c;
}
}
if (goaldiff[1]!=goaldiff[2])
cout<<teamname[0]<<" "<<teamname[1]<<endl;
else
{
if(totalgoals[1]>totalgoals[2])
cout<<teamname[0]<<" "<<teamname[1]<<endl;
else if(totalgoals[1]<totalgoals[2])
cout<<teamname[0]<<" "<<teamname[2]<<endl;
else cout<<"NO"<<endl;
}
}
else if (score[0]!=score[1]&&score[1]==score[2]&&score[2]==score[3])
{
for(i=1; i<3; i++)
for(j=i+1; j<4; j++)
{
if(goaldiff[j]>goaldiff[i])
{
t1=score[i];
score[i]=score[j];
score[j]=t1;
t2=goaldiff[i];
goaldiff[i]=goaldiff[j];
goaldiff[j]=t2;
t3=totalgoals[i];
totalgoals[i]=totalgoals[j];
totalgoals[j]=t3;
c=teamname[i];
teamname[i]=teamname[j];
teamname[j]=c;
}
}
if (goaldiff[1]!=goaldiff[2])
cout<<teamname[0]<<" "<<teamname[1]<<endl;
else if(goaldiff[1]==goaldiff[2]&&goaldiff[2]!=goaldiff[3])
{
if(totalgoals[1]>totalgoals[2])
cout<<teamname[0]<<" "<<teamname[1]<<endl;
else if(totalgoals[1]<totalgoals[2])
cout<<teamname[0]<<" "<<teamname[2]<<endl;
else cout<<"NO"<<endl;
}
else if (goaldiff[1]==goaldiff[2]&&goaldiff[2]==goaldiff[3])
{
for(i=1; i<3; i++)
for(j=i+1; j<4; j++)
{
if(totalgoals[j]>totalgoals[i])
{
t1=score[i];
score[i]=score[j];
score[j]=t1;
t2=goaldiff[i];
goaldiff[i]=goaldiff[j];
goaldiff[j]=t2;
t3=totalgoals[i];
totalgoals[i]=totalgoals[j];
totalgoals[j]=t3;
c=teamname[i];
teamname[i]=teamname[j];
teamname[j]=c;
}
}
if(totalgoals[1]!=totalgoals[2])
cout<<teamname[0]<<" "<<teamname[1]<<endl;
else cout<<"NO"<<endl;
}
}
else if(score[1]==score[2]&&score[0]==score[1]&&score[2]==score[3])
{
for(i=0; i<3; i++)
for(j=i+1; j<4; j++)
{
if(goaldiff[j]>goaldiff[i])
{
t1=score[i];
score[i]=score[j];
score[j]=t1;
t2=goaldiff[i];
goaldiff[i]=goaldiff[j];
goaldiff[j]=t2;
t3=totalgoals[i];
totalgoals[i]=totalgoals[j];
totalgoals[j]=t3;
c=teamname[i];
teamname[i]=teamname[j];
teamname[j]=c;
}
}
if(goaldiff[1]!=goaldiff[2])
cout<<teamname[0]<<" "<<teamname[1]<<endl;
else if (goaldiff[0]!=goaldiff[1]&&goaldiff[1]==goaldiff[2]&&goaldiff[2]!=goaldiff[3])
{
if(totalgoals[1]>totalgoals[2])
cout<<teamname[0]<<" "<<teamname[1]<<endl;
else if(totalgoals[1]<totalgoals[2])
cout<<teamname[0]<<" "<<teamname[2]<<endl;
else cout<<"NO"<<endl;
}
else if (goaldiff[0]!=goaldiff[1]&&goaldiff[1]==goaldiff[2]&&goaldiff[2]==goaldiff[3])
{
for(i=1; i<3; i++)
for(j=i+1; j<4; j++)
{
if(totalgoals[j]>totalgoals[i])
{
t1=score[i];
score[i]=score[j];
score[j]=t1;
t2=goaldiff[i];
goaldiff[i]=goaldiff[j];
goaldiff[j]=t2;
t3=totalgoals[i];
totalgoals[i]=totalgoals[j];
totalgoals[j]=t3;
c=teamname[i];
teamname[i]=teamname[j];
teamname[j]=c;
}
}
if (totalgoals[1]!=totalgoals[2])
cout<<teamname[0]<<" "<<teamname[1]<<endl;
else cout<<"NO"<<endl;
}
else if(goaldiff[0]==goaldiff[1]&&goaldiff[1]==goaldiff[2]&&goaldiff[2]!=goaldiff[3])
{
for(i=0; i<2; i++)
for(j=i+1; j<3; j++)
{
if(totalgoals[j]>totalgoals[i])
{
t1=score[i];
score[i]=score[j];
score[j]=t1;
t2=goaldiff[i];
goaldiff[i]=goaldiff[j];
goaldiff[j]=t2;
t3=totalgoals[i];
totalgoals[i]=totalgoals[j];
totalgoals[j]=t3;
c=teamname[i];
teamname[i]=teamname[j];
teamname[j]=c;
}
}
if(totalgoals[0]!=totalgoals[1]&&totalgoals[1]!=totalgoals[2])
cout<<teamname[0]<<" "<<teamname[1]<<endl;
else cout<<"NO"<<endl;
}
else if(goaldiff[0]==goaldiff[1]&&goaldiff[1]==goaldiff[2]&&goaldiff[2]==goaldiff[3])
{
for(i=0; i<3; i++)
for(j=i+1; j<4; j++)
{
if(totalgoals[j]>totalgoals[i])
{
t1=score[i];
score[i]=score[j];
score[j]=t1;
t2=goaldiff[i];
goaldiff[i]=goaldiff[j];
goaldiff[j]=t2;
t3=totalgoals[i];
totalgoals[i]=totalgoals[j];
totalgoals[j]=t3;
c=teamname[i];
teamname[i]=teamname[j];
teamname[j]=c;
}
}
if(totalgoals[1]!=totalgoals[2])
cout<<teamname[0]<<" "<<teamname[1]<<endl;
else cout<<"NO"<<endl;
}
}
}
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;
}

YTU 2615: AB编程题--世界杯小组赛的更多相关文章

  1. YTU 2598: 编程题B-小平智斗自动售货机

    2598: 编程题B-小平智斗自动售货机 时间限制: 1 Sec  内存限制: 128 MB 提交: 268  解决: 69 题目描述 LYH自动售货机在销售商品时,具有自动找钱功能.但是找零的最小单 ...

  2. YTU 2597: 编程题B-选拔飞行员

    2597: 编程题B-选拔飞行员 时间限制: 1 Sec  内存限制: 128 MB 提交: 131  解决: 35 题目描述 2100年空军选拔高中生飞行学员基本条件要求如下,年龄范围:16-19周 ...

  3. YTU 2596: 编程题B-日期格式

    2596: 编程题B-日期格式 时间限制: 1 Sec  内存限制: 128 MB 提交: 981  解决: 74 题目描述 注:本题只需要提交编写的函数部分的代码即可. 将输入的日期格式 月/日/年 ...

  4. YTU 2858: 编程题AB-骨牌铺方格

    2858: 编程题AB-骨牌铺方格 时间限制: 1 Sec  内存限制: 128 MB 提交: 87  解决: 23 题目描述 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出 ...

  5. YTU 2845: 编程题AB-卡片游戏

    2845: 编程题AB-卡片游戏 时间限制: 1 Sec  内存限制: 128 MB 提交: 30  解决: 13 题目描述 小明对数字的序列产生了兴趣: 现有许多张不同的数字卡片,用这若干张卡片能排 ...

  6. YTU 2837: 编程题B-狐狸算卦

    2837: 编程题B-狐狸算卦 时间限制: 1 Sec  内存限制: 128 MB 提交: 76  解决: 52 题目描述 注:本题只需要提交需要完善部分的代码,请按照C++方式提交. 小熊和狐狸是邻 ...

  7. YTU 2640: 编程题:运算符重载---矩阵求和

    2640: 编程题:运算符重载---矩阵求和 时间限制: 1 Sec  内存限制: 128 MB 提交: 484  解决: 190 题目描述 /* 有两个矩阵a和b,均为2行3列.求两个矩阵之和. 重 ...

  8. YTU 2795: 编程题AB-侦察员的密码

    2795: 编程题AB-侦察员的密码 时间限制: 1 Sec  内存限制: 128 MB 提交: 155  解决: 43 题目描述 侦察员小甲在被捕前在墙上写了两行文字(ASCII字符),其中包含了他 ...

  9. POJ C程序设计进阶 编程题#3:运算符判定

    编程题#3:运算符判定 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 两个 ...

随机推荐

  1. 设计模式之观察者模式(Observer)

    观察者模式原理:当有新的消息产生时发送给观察者,和中介者模式的不同地方是中介者模式强调中介的作用以及中介双方的交互,观察者模式是主动调用观察者成员函数进行消息发送. 代码如下: #include &l ...

  2. 【BZOJ】【3442】学习小组

    网络流/费用流 orz zyf 裸的费用流,根据题目描述即可建出如下的图: S->i 费用表示每有一个加入第 i 个小组的学生,需要花的钱,由于是跟流量(人数)的二次方相关,所以要拆边……然后每 ...

  3. PHP操作数据库类

    <?php /** * 功能: 数据库操作类 . * 作者: 赵铭哲 * 日期: 2016-05-23 * 时间: 9:43 */ namespace ZH\DataBase; use \Exc ...

  4. javascript高级函数

    高级函数 安全的类型检测 js内置的类型检测并非完全可靠,typeof操作符难以判断某个值是否为函数 instanceof在多个frame的情况下,会出现问题. 例如:var isArray = va ...

  5. Linux 配置网络

    1.vi  /etc/sysconfig/network-scripts/ifcfg-eth0 2. # Advanced Micro Devices [AMD] 79c970 [PCnet32 LA ...

  6. BZOJ 1029 [JSOI2007] 建筑抢修(贪心)

    1029: [JSOI2007]建筑抢修 Time Limit: 4 Sec  Memory Limit: 162 MBSubmit: 2285  Solved: 1004[Submit][Statu ...

  7. code::blocks 初使用遇到的问题记录

    /* 做本程序遇到的问题:由于使用的是CODE::BLOCKS 开发环境,刚开始使用code::blocks是,什么都 没有设置,居然输入的中文字符串,保存项目后,再次打开,code::blocks不 ...

  8. ZOJ3554 A Miser Boss(dp)

    给你n个工件,然后有A,B,C三个工厂,然后它们加工第i个工件所需要的时间分别为a[i],b[i],c[i],然后现在要你利用三间工厂加工所有的零件,要求是任何时间工厂都不能停工,而且一定要三间同时做 ...

  9. POJ 2105

    #include <iostream> #include <cmath> #include <string> using namespace std; int ma ...

  10. Codeforces Round #263 (Div. 2) D. Appleman and Tree(树形DP)

    题目链接 D. Appleman and Tree time limit per test :2 seconds memory limit per test: 256 megabytes input ...